Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
C#
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
Updated 11-Oct-12 15:16pm
v2
Comments
Member 9291223 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");
}


}

Try setting autopostback = true in gridview
 
Share this answer
 
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
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900