Creating a Textbox dynamically in for loop

前端 未结 3 1439
别那么骄傲
别那么骄傲 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条回答
  •  梦毁少年i
    2021-01-28 07:55

    I think you may have meant to do this:

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

提交回复
热议问题