Click here to Skip to main content
Sign Up to vote bad
good
See more: SQL2005C#ASP.NET
Dear sir,
 
I want to Display three dropwnlist in gridview.
First DropdownList As Country.
Second DropdownList As State.
third DropdownList As District.
How to bind multiple DropDownList in Gridview in asp.net?
Then
How to implement cascading of Dropdownlist in Gridview in asp.net?
 
Please You will send link or Code.
 
Thanks
Mahendra Kumar Das
Posted 4 Apr '11 - 22:56


5 solutions

i have Typed that in Google[How to implement cascading of Dropdownlist in Gridview in asp.net]
 
and got number Of results First try to figure it out by yourself and then ask for suggetions
Or errors
 

Try this Link
 
Link [^]
  Permalink  
Hi Mahendra,
 
Try this,
 

First you have to create 3 DropDown into your aspx page and set AutoPostBack="ture" and also it's OnCheckedChanged Event which will call code behind function.
 
First in Page load you have to bind Country DropDown and on Country DropDown OnCheckedChanged event you have to bind State DropDown and on State DropDown OnCheckedChanged event you have to bind City DropDown .
 
Like This,
 
On .Aspx Page :=
 
<asp:DropDownList ID="ddlCountry" runat="server" Width="100%" AutoPostBack="true"
                                                       CausesValidation="false" 
                                                       OnSelectedIndexChanged="ddlCountry_SelectedIndexChanged" CssClass="divisionClass">
                                                   </asp:DropDownList>
 

<asp:DropDownList ID="ddlState" runat="server" AutoPostBack="true" Width="100%" OnSelectedIndexChanged="ddlState_SelectedIndexChanged"
                                                        CausesValidation="false"  CssClass="divisionClass">
                                                    </asp:DropDownList>
<asp:DropDownList ID="ddlCity" runat="server" AutoPostBack="true" Width="100%" OnSelectedIndexChanged="ddlCity_SelectedIndexChanged"
                                                        CausesValidation="false"  CssClass="divisionClass">
                                                    </asp:DropDownList>
 

On Code Behind Page that is .cs :=
 
In Page Load Write Below Function :
 
ddlCountry.DataSource = fn_getCountry()
            ddlCountry.DataTextField = "CountryName"
            ddlCountry.DataValueField = "CountryID"
            ddlCountry.DataBind()
            ddlCountry.Items.Insert(0, New ListItem("Select Country", ""))
            ddlState.Items.Insert(0, New ListItem("Select State", ""))
            ddlCity.Items.Insert(0, New ListItem("Select City", ""))
            ddlState.Enabled = False
            ddlCity.Enabled = False
 
then
 
protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
{
<pre lang="sql">ddlState.DataSource = fn_getStateByCountryID(countryID)
                ddlState.DataTextField = "StateName"
                ddlState.DataValueField = "StateID"
                ddlState.DataBind()
                ddlState.Items.Insert(0, New ListItem("Select State", ""))
                ddlCity.SelectedIndex = 0
                ddlState.Enabled = True
                ddlCity.Enabled = False
 

}  

protected void ddlState_SelectedIndexChanged(object sender, EventArgs e)
{
 
<pre lang="sql">ddlCity.DataSource = fn_getCityByStateID(stateID)
                ddlCity.DataTextField = "CityName"
                ddlCity.DataValueField = "CityID"
                ddlCity.DataBind()
                ddlCity.Items.Insert(0, New ListItem("Select City", ""))
                ddlCity.Enabled = True
 
}  

protected void ddlCity_SelectedIndexChanged(object sender, EventArgs e)
{
 
}
 

Here,
fn_getCountry is a function which will Execute a query and Holding a list of Country.
fn_getStateByCountryID(countryID) is function which will hold a State list of Selected Country.
and
fn_getCityByStateID(stateID) is function which will hold a City list of Selected State.
 
All d Best,
 
I Hope this will help You.
  Permalink  
Well there is a control named:
ASP.NET AJAX Cascading Drop Down Control Smile | :) you can implement it easily;
AJAX Cascading Drop Down Control[^]
AJAX Cascading Drop Down with Database[^]
A video tutorial[^]
A similar example that you may want to look[^]
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 239
1 OriginalGriff 188
2 Mahesh Bailwal 139
3 Maciej Los 135
4 Aarti Meswania 98
0 Sergey Alexandrovich Kryukov 10,214
1 OriginalGriff 7,819
2 CPallini 4,181
3 Rohan Leuva 3,522
4 Maciej Los 3,089


Advertise | Privacy | Mobile
Web03 | 2.6.130523.1 | Last Updated 9 Jul 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid