Click here to Skip to main content
15,902,032 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
I have a gridview with two dropdowns country and state when i click on edit button the dropdowns selected values should be displayed on edit mode please give some samples or code..


Thanks in Advance..
Raghu.
Posted

Go to your RowDataBound Event of GridView, Find the DropDownList which is in EditItemTemplate and bind the data and set the selected value there.
Try this:
C#
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        DropDownList ddlCountry = e.Row.FindControl("ddlCountry") as DropDownList;

        if (ddlCountry != null){
            // Write your code to bind dropdownlist and set it's selected value here.
        }
    }
}

OR
See and example here for Binding DropDownList in GridView RowEditing Command[^].


--Amit
 
Share this answer
 
v2
Comments
Madhugundi 15-Mar-13 4:37am    
its working fine for one dropdown list but i need this to multiple dropdowns
_Amy 15-Mar-13 4:39am    
No Problem. Based on selected value of Country dropdownlist you need to fetch the data for states dropdownlist and then bind the state dropdownlist with filtered data. And then try to set the selected value.

--Amit
Madhugundi 15-Mar-13 4:42am    
please give sample code i tried hard but not getting
_Amy 15-Mar-13 4:43am    
Where you are having the data for states? In Session or DataBase?
Madhugundi 15-Mar-13 4:43am    
database
Hi,

i think it may be help ful for u

Editable GridView in ASP.NET 2.0[^]
 
Share this answer
 
v2
Comments
Madhugundi 15-Mar-13 5:02am    
thanks to consider my post please look at my post i am searching for multiple dropdownlists on gridview with editable
Dhritirao's 15-Mar-13 5:05am    
in that link also there are two drop down in editable only
Madhugundi 15-Mar-13 5:23am    
this is not suitable for my post i checked this code only one dropdownlist selected value only selected on editmode another one is not selected please look at code

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