By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,653 Members | 1,269 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,653 IT Pros & Developers. It's quick & easy.

adding dynamically generated dropdownlist to table and getting its selected value

P: 20

I am having a problem of getting the value from the dynamically generated table and dropdownlist. What I am facing is, I have created a table in the aspx page and now I need to add values to the the cells of the table respectively which I have done easily but the problem is when I add the dynamically generated dropdownlist to the cell I cannot read the value from the dropdownlist.
For adding the dropdownlist in the cell I have done the following:


When I perform the above action I can view the dropdownlist in the table but cannot get the value from the dropdownlist.

So how can this be done?

DropDownList ddl = new DropDownList();
ddl.ID = "drop" + j;
ddl.Items[0].Selected = true;
TableRow r = new TableRow();
TableCell c = new TableCell();

Table1 is the table that I defined at aspx page

Any help is appreciated
Mar 27 '08 #1
Share this Question
Share on Google+
2 Replies

Expert 100+
P: 797
Is this what you're looking for? Works on my system...

Mar 27 '08 #2

P: 20
Is this what you're looking for? Works on my system...

Your's solution could have been correct if there was only one dropdownlist but i generate a dropdownlist at each row of the table so Here's is where I am
I want to get first get to the particular row and then its cell and then get the selected value at the dropdownlist.
For that i have the following line of code:
string str = ((DropDownList)(table.Rows[i].Cells[2].FindControl("drop" + i))).SelectedItem.Value;

But the problem here is I get only the first item in the dropdownlist whatever the case may be even when I select other listitems.

So any idea, but thanks for replying so soon.
Mar 27 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.