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
| I want to add here the textbox | |
| I want to add here the drop downlist | |
| I want to add here the radiobutton |
please help me how to do this with form1.controls.add or any other best way is there to acieve this then tellme that
mohdazeemuddin ahmedPosted Apr 7, 2010, 9:14 AM
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();
Table Table1 = new Table();
Table1.ID = "DynamicTable";
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
TableRow tr1 = new TableRow();
for(int j=0;j
TableCell tc1 =new TableCell();
if (ds.Tables[0].Rows[i][0].ToString() == "TextBox")
{
TextBox tb = new TextBox();
tb.ID = "txtbx1"+i+""+j;
tb.Text = "Pramod";
tc1.Controls.Add(tb);
tr1.Cells.Add(tc1);
}
if (ds.Tables[0].Rows[i][0].ToString() == "DropDownList")
{
DropDownList ddl = new DropDownList();
ddl.ID="ddl1"+i+""+j;
ddl.Items.Add("pramod");
ddl.Items.Add("kishore");
tc1.Controls.Add(ddl);
tr1.Cells.Add(tc1);
}
if (ds.Tables[0].Rows[i][0].ToString() == "RadioButton")
{
RadioButton rd = new RadioButton();
rd.ID = "rd1"+i+""+j;
tc1.Controls.Add(rd);
tr1.Cells.Add(tc1);
}
}
Table1.Rows.Add(tr1);
}
form1.Controls.Add(Table1);
}
try this