Click here to Skip to main content
Rate this: bad
good
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;
 
                
            }
 

        }
 
thanks
Posted 11-Oct-12 14:54pm
Edited 11-Oct-12 15:16pm
Wes Aday79.5K
v2
Comments
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
good
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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Try setting autopostback = true in gridview
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 345
1 _Amy 210
2 Peter Leow 175
3 Nirav Prabtani 167
4 Andreas Gieriet 160
0 OriginalGriff 7,540
1 Sergey Alexandrovich Kryukov 6,597
2 Maciej Los 3,849
3 Peter Leow 3,653
4 CHill60 2,712


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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100