Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C#3.0
How to we actually get the value of the selected item in a dropdownlist.The dropdownlist is in an item template of a griw view.
The following code does gets the value but its always theh first item in the dropdownlist:
protected void viewfiles(object sender, GridViewCommandEventArgs e)
 if (e.CommandName == "savefiles")
            if (Page.IsPostBack)
                int Index = Convert.ToInt32(e.CommandArgument);
                GridViewRow row = gvunclassified.Rows[Index];
                DropDownList Offices = row.FindControl("DDept") as DropDownList;
                String deparmentname = (Offices is DropDownList) ? Offices.SelectedValue : null;

Posted 11-Oct-12 14:54pm
Edited 11-Oct-12 15:16pm
Member 9291223 at 11-Oct-12 22:34pm
I have even tried doing it this way but still again teh first value remains selected: if (Page.IsPostBack==true) { //int currentIndex = gvunclassified.EditIndex; //gvunclassified.EditIndex = -1; int index = Convert.ToInt32(e.CommandArgument); GridViewRow row = gvunclassified.Rows[index]; try { string value2 = ((DropDownList)row.FindControl("DDept")).SelectedItem.ToString(); } catch { Response.Write("error"); } }
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Try setting autopostback = true in gridview
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I had also same problem.
then i have put a hidden field in the page and change the value in java script of obchnage event of combo box

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
0 Shai Vashdi 1,448
1 Tadit Dash 270
2 OriginalGriff 223
3 Sergey Alexandrovich Kryukov 215
4 Peter Leow 180
0 Sergey Alexandrovich Kryukov 9,440
1 OriginalGriff 5,618
2 Peter Leow 4,280
3 Maciej Los 3,540
4 Abhinav S 3,363

Advertise | Privacy | Mobile
Web02 | 2.8.140415.2 | Last Updated 12 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid