Hi,
I
have created a table of textboxes dynamically with a constant 8 column
but the row value keeps changing with the corresponding selection from
the dropdown.
I want to fill these textboxes as they are created dynamically from SQL database,
but I am not sure on how to refer them in order to bind them with the database.
I ll attach a part of the code here. plz look into it and help me.
PlaceHolder1.Controls.Clear();
Table table = new Table();
table.ID = "Table1";
PlaceHolder1.Controls.Add(table);
// Now iterate through the table and add your controls
for (int i = 0; i < rowsCount; i++)
{
TableRow row = new TableRow();
for (int j = 0; j < 8; j++)
{
TableCell cell = new TableCell();
TextBox tb = new TextBox ();
// Set a unique ID for each TextBox added
tb.ID = "TextBoxRow_" + i + "Col_" + j;
// Add the control to the TableCell
SqlConnection cnn = new SqlConnection("Data Source=MPMSQLDEV;nitial Catalog=ASN;User ID=sa;Password=marcal");
cnn.Open();
SqlCommand cmmd = new SqlCommand("SELECT polinenum,marcalitem,
vendornum, itemdesc, qtyunit, noroll, totqty, unit FROM asnvendor WHERE
(vendorno ='" + TextBox116.Text + "') AND (ponumber ='" +
TextBox117.Text + "')", cnn);
SqlDataReader dar = cmmd.ExecuteReader();
while (dar.Read())
{
//???????????????????????????????????????????????????????????????????????
}
cnn.Close();
cell.Controls.Add(tb);
// Add the TableCell to the TableRow
row.Cells.Add(cell);
}
// Add the TableRow to the Table
table.Rows.Add(row);
}
I
hope I am clear, pls let me know the possible answer, the 8 columns are
bound to different fields as per the select statement and the following
number of rows are bound to the same fields of the as per the
columns...
Thanks in advance
Aaditya
Loading
knightsPosted Jan 25, 2011, 11:30 AM
Aaditya GanesanPosted Jan 25, 2011, 10:28 AM
Thanks for the efforts, I got the ans from rivdiv from ASP.net forums. I have attached the code for some1 in need
Aaditya GanesanPosted Jan 25, 2011, 9:52 AM
Thanks for the reply, First this is a Web application and does it work the same way you said for the web as well.
second can you be a little more clear on how to go about this problem.
Thank you
Adi
Jean PaulPosted Jan 25, 2011, 4:28 AM
According to my understanding I am preferring the following.
When you dynamically create the textboxes the first time, set the tag property of the text box to the field name.
So next time you can iterate through the form.Controls array and find those textboses whose tag is not null.
I hope this is a windows application: if so you can use the following query:
this.Controls.OfType
Once you find the textbox, you can use the tag property - convert to string and set the value based on your row.
Regards,
JP