469,588 Members | 2,688 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,588 developers. It's quick & easy.

adding dynamically generated dropdownlist to table and getting its selected value

20
Hi

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:

cellName.controls.add(dropdownlistName);

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.Clear();
ddl.Items.Add("PP");
ddl.Items.Add("PD");
ddl.Items.Add("DP");
ddl.Items.Add("DD");
ddl.Items[0].Selected = true;
TableRow r = new TableRow();
TableCell c = new TableCell();
c.Controls.Add(ddl);
r.Cells.Add(c);
Table1.Rows.Add(r);

Table1 is the table that I defined at aspx page

Any help is appreciated
Mar 27 '08 #1
2 3123
balabaster
797 Expert 512MB
Is this what you're looking for? Works on my system...

Response.Write(ddl.SelectedItem.Text);
Mar 27 '08 #2
mylog
20
Is this what you're looking for? Works on my system...

Response.Write(ddl.SelectedItem.Text);
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.

Similar topics

5 posts views Thread by Mike | last post: by
1 post views Thread by mitchman10 | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.