Assign Dynamic Textbox :
protected void Page_Load(object sender, EventArgs e)
{
//Nilay 27 April 2011
//LIMS Application
DataTable dt;
dt = data("Select * from SC_SVL_ClientSpecificField");
Table table = new Table();
//table.ID = "Table1";
table.Width = new Unit(500, UnitType.Pixel);
Page.Form.Controls.Add(table);
// Now iterate through the table and add your controls
for (int i = 0; i < dt.Rows.Count; i++)
{
TableRow row = new TableRow();
row.Width = new Unit(300, UnitType.Pixel);
TableCell cell = new TableCell();
TableCell cell1 = new TableCell();
for (int j = 0; j < dt.Rows.Count-4; j++)
{
Label lb = new Label();
lb.Text = dt.Rows[i]["ClientSpecificField"] + ":";
cell1.Controls.Add(lb);
cell1.Width = new Unit(10, UnitType.Pixel);
row.Cells.Add(cell1);
table.Rows.Add(row);
}
TextBox tb = new TextBox();
// Set a unique ID for each TextBox added
tb.ID = dt.Rows[0]["ClientSpecificField"] + ":" + "TextBoxRow_" + i + "Col_" + i;
//tb.Text = dt.Rows[0]["ClientSpecificField"];
// Add the control to the TableCell
cell.Width = new Unit(20, UnitType.Pixel);
cell.Controls.Add(tb);
row.Width = new Unit(800, UnitType.Pixel);
// Add the TableCell to the TableRow
row.Cells.Add(cell);
// Add the TableRow to the Table
table.Rows.Add(row);
}
}
public DataTable data(string strsql)
{
DataTable dt;
DataSet ds = new DataSet();
con.Open();
SqlDataAdapter adpt = new SqlDataAdapter(strsql, con);
adpt.Fill(ds);
dt = ds.Tables[0];
con.Close();
return dt;
}
No comments:
Post a Comment