How to dynamically add rows to a table in ASP.NET?

前端 未结 10 966
谎友^
谎友^ 2020-12-23 22:20

So today I started learning ASP.NET. Unfortunately I haven\'t found any good tutorials online, and I can\'t afford to buy books at the moment, so I\'ve had to create a ASP.N

相关标签:
10条回答
  • 2020-12-23 22:40

    You need to use JavaScript in your HTML and make sure you are using forms so that. You may finally serialize the data using Ajax method to push the data from HTML into database

    0 讨论(0)
  • 2020-12-23 22:42

    You can use the asp:Table in your web form and build it via code:

    http://msdn.microsoft.com/en-us/library/7bewx260.aspx

    Also, check out asp.net for tutorials and such.

    0 讨论(0)
  • 2020-12-23 22:42

    Dynamically Created for a Row in a Table

    See below the Link

    http://msdn.microsoft.com/en-us/library/7bewx260(v=vs.100).aspx

    0 讨论(0)
  • 2020-12-23 22:43

    You need to get familiar with the idea of "Server side" vs. "Client side" code. It's been a long time since I had to start, but you may want to start with some of the video tutorials at http://www.asp.net.

    Two things to note: if you're using VS2010 you actually have two different frameworks to chose from for ASP.NET: WebForms and ASP.NET MVC2. WebForms is the old legacy way, MVC2 is being positioned by MS as an alternative not a replacement for WebForms, but we'll see how the community handles it over the next couple of years. Anyway, be sure to pay attention to which one a given tutorial is talking about.

    0 讨论(0)
  • 2020-12-23 22:50
    public partial class result : System.Web.UI.Page
    {
        static DataTable table1 = new DataTable("Shashank");
        static DataSet set = new DataSet("office");
    
    
        protected void Page_Load(object sender, EventArgs e)
        {
            lblEmployeeNumber.Text = HttpContext.Current.Request.Form["txtEmployeeNumber"];
            lblFirstName.Text = Request.Form["txtFirstName"];
            lblLastName.Text = Request.Form["txtLastName"];
            lblTitle.Text = Request.Form["txtTitle"];
    
            Int32 Rcount = Convert.ToInt32(table1.Rows.Count);
    
            if (Rcount == 0)
            {
    
                table1.Columns.Add("ID");
                table1.Columns.Add("FName");
                table1.Columns.Add("LName");
                table1.Columns.Add("Title");
                table1.Rows.Add(lblEmployeeNumber.Text, lblFirstName.Text, lblLastName.Text, lblTitle.Text);
                set.Tables.Add(table1);
            }
            else
            {
                if (lblEmployeeNumber.Text != "")
                {
                    DataRow dr = table1.NewRow();
                    dr["ID"] = lblEmployeeNumber.Text;
                    dr["FName"] = lblFirstName.Text;
                    dr["LName"] = lblLastName.Text;
                    dr["Title"] = lblTitle.Text;
                    table1.Rows.Add(dr);
                }
            }
    
            gvrEmp.DataSource = set;
            gvrEmp.DataBind();
    
        }
    }
    
    0 讨论(0)
  • 2020-12-23 22:52
    <html>
    <head>
      <title>Row Click</title>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
      <script>
            function test(){
                alert('test');
            }
      $(document).ready(function(){
            var row='<tr onclick="test()"><td >Value 4</td><td>Value 5</td><td>Value 6</td></tr>';
            $("#myTable").append(row);
    });
      </script>
    </head>
    <table id="myTable" >
    <th>Column 1</th><th>Column 2</th><th>Column 3</th>
    <tr onclick="test()">
        <td >Value 1</td>
        <td>Value 2</td>
        <td>Value 3</td>
    </tr>
    </table>
    </html>
    
    0 讨论(0)
提交回复
热议问题