Click here to Skip to main content
15,891,976 members
Please Sign up or sign in to vote.
3.67/5 (2 votes)
See more:
Hi,

I have a grid view
IN That i have dropdown list i have to select a Employee from the dropdown list. and i want to get The dropdown list selected value . pls help
Posted
Comments
Karthik_Mahalingam 15-Jan-14 3:30am    
during edit ??

You can try
C#
DropDownList ddlEmployee = GridView1.Rows(<index_of_the_row>).FindControls("ddlEmployee") as DropDownList;

object selectedValue = ddlEmployee.SelectedValue;
 
Share this answer
 
v2
Comments
parithi vr 15-Jan-14 3:54am    
The Real thing is when i select the data in dropdownlist and when i click the Edit button The dropdown list in gridview changed to its drodownlist.selectedindex=0; how can i stop the postback
Deviprasad Das 15-Jan-14 5:20am    
Can you please provide a piece of your code?
Dinesh.V.Kumar 28-Jan-14 6:38am    
While you click the edit button, kindly do another rebind...
try this.

C#
protected void gridView_RowEditing(object sender, GridViewEditEventArgs e)
        {
            int index = e.NewEditIndex;
            var ddl = gridView.Rows[index].FindControl("YourDropdownlistname") as DropDownList;
            string text = ddl.SelectedItem.Text;
            string value = ddl.SelectedItem.Value;
        }
 
Share this answer
 
Comments
parithi vr 15-Jan-14 3:53am    
The Real thing is when i select the data in dropdownlist and when i click the Edit button The dropdown list in gridview changed to its drodownlist.selectedindex=0; how can i stop the postback
Karthik_Mahalingam 15-Jan-14 3:58am    
you should bind your data
inside
if( !page.ispostback){ // your code to bind gridview}
Member 14171200 9-Nov-19 2:54am    
Thanks for this solution :)
set autopostback as 'false' for dropdown.

C#
<asp:dropdownlist id="DropDownList1" runat="server" autopostback="false"  /> 
 
Share this answer
 
v2

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