adding server side conrols dynamically on the aspx page
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["conn"].ToString();
con.Open();
SqlDataAdapter da = new SqlDataAdapter("select controlname from tbl", con);
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
if (ds.Tables[0].Rows[i][0].ToString() == "TextBox")
{
TextBox tb = new TextBox();
tb.ID = "txtbx1";
tb.Text = "Pramod";
form1.Controls.Add(tb);
}
if (ds.Tables[0].Rows[i][0].ToString() == "DropDownList")
{
DropDownList ddl = new DropDownList();
ddl.ID="ddl1";
ddl.Items.Add("pramod");
ddl.Items.Add("kishore");
form1.Controls.Add(ddl);
}
if (ds.Tables[0].Rows[i][0].ToString() == "RadioButton")
{
RadioButton rd = new RadioButton();
rd.ID = "rd1";
form1.Controls.Add(rd);
}
}
}
hi iam adding the textbox ,dropdownlist,radiobutton dynamically on aspx page using the above code then
but it is adding the controls on the page from first position
but i want to add the particular control in particular column of a table row
<table><tr><td></td><td>I want to add here the textbox</td></tr>
<tr><td></td><td>I want to add here the drop downlist</td></tr>
<tr><td></td><td>I want to add here the radiobutton</td></tr>
</table>
please help me how to do this with form1.controls.add or any other best way is there to acieve this then tellme that