TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Pramod Kumar Nandagiri
NA
484
0
adding server side conrols dynamically on the aspx page
Apr 6 2010 9:08 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();
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
Reply
Answers (
1
)
How to handle selectedIndex changed throws an exception?
SlipContainer & Panel question: