adding dynamically generated dropdownlist to table and getting its selected value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mylog
    New Member
    • Sep 2007
    • 20

    adding dynamically generated dropdownlist to table and getting its selected value

    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.contro ls.add(dropdown listName);

    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
  • balabaster
    Recognized Expert Contributor
    • Mar 2007
    • 798

    #2
    Is this what you're looking for? Works on my system...

    Response.Write( ddl.SelectedIte m.Text);

    Comment

    • mylog
      New Member
      • Sep 2007
      • 20

      #3
      Originally posted by balabaster
      Is this what you're looking for? Works on my system...

      Response.Write( ddl.SelectedIte m.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("d rop" + i))).SelectedIt em.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.

      Comment

      Working...