Reputation:
I have generated some questions from a dataset with textboxes next to them in a dynamically generated html table. I have 5 questions and 5 textboxes. So, i need to get back the values of some textboxes.
I am looping through the dataset and adding a series of questions with textboxes next to them. However, do i need to generate some unique ID to each textbox?
private void GenerateTable(int colsCount, int rowsCount, DataSet ds, DataSet ds2)
{
if (!IsPostBack)
{
int counter = 0;
List<TableRow> tableRowList = new List<TableRow>();
List<TableCell> tableCellList = new List<TableCell>();
List<Control> controlsList = new List<Control>();
foreach (DataTable dataTable in ds.Tables)
{
foreach (DataRow dataRow in dataTable.Rows)
{
TableRow tableRow = new TableRow();
TableCell tableCell = new TableCell();
TableCell tableCell2 = new TableCell();
TextBox textbox = new TextBox();
//textbox.ID = "TextBoxID";
TableRow tableRow2 = new TableRow();
TableCell tableCel2 = new TableCell();
tableCell.Text = dataRow["QUESTIONTEXT"].ToString();
if (dataRow["TYPEID"].ToString() == "1")
{
tableCell2.Controls.Add(textbox);
controlsList.Add(textbox);
}
tableRow.Cells.Add(tableCell);
tableRow.Cells.Add(tableCell2);
myTable.Rows.Add(tableRow);
tableRowList.Add(tableRow);
tableCellList.Add(tableCell);
tableCellList.Add(tableCell2);
counter++;
}
}
//TextBox tb = myTable.FindControl(TextBoxID) as TextBox;
Upvotes: 0
Views: 640
Reputation: 150253
Do I need to generate some unique ID to each textbox?
Yes... id must be unique. a page with more than one element with the same id is invaliid
spec:
id=name [CS]
This attribute assigns a name to an element. This name must be unique in a document.
But if you are not using the id
at all you can just not assign id at all...
Upvotes: 1