Creating a Textbox dynamically in for loop

前端 未结 3 1438
别那么骄傲
别那么骄傲 2021-01-28 07:19

I was trying to create a table dynamically and put textboxes in it. Here in the following code, i was trying to create a textbox with a distinct name for each k. But only the l

3条回答
  •  深忆病人
    2021-01-28 07:54

    Replace this line

    dsmissing.Tables[0].Rows[tblCols- 1]["NewCompanyName"].ToString();
    

    With

    dsmissing.Tables[0].Rows[k]["NewCompanyName"].ToString();
    

    I assume you are talking about ID like below.

    for (int k = 0; k < tblCols; k++)
    {
        TableCell tc = new TableCell(); 
        TextBox txtCompanyName = new TextBox();
        txtCompanyName.Text = dsmissing.Tables[0].Rows[k]["NewCompanyName"].ToString();
        txtCompanyName.ID = Guid.NewGuid().ToString("N");
        tc.Controls.Add(txtCompanyName);
    }
    

提交回复
热议问题