hi my req is like this
in database i will have a talbe like this
s.no controlname
1 Textbox
2 Dropdownlist
3. Radiobutton
by reading the names of the server side controls from the database i have to create the server side controls runtime with a button click
if i change the order of serverside controls in the database then the order of server side contols to be created on aspx page must have to change
Means according to the table data the server side controls to be created dynamically
please help me on this
Loading
Pramod Kumar NandagiriPosted Apr 6, 2010, 9:10 AM
{
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
please help me how to do this with form1.controls.add or any other best way is there to acieve this then tellme that