aspdotnet-suresh offers articles and tutorials,csharp dot net, articles and tutorials,VB.NET Articles,Gridview articles,code examples of 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

how to implement cascading dropdownlist in gridview using

Nov 12, 2011

In this article I will explain how to implement cascading dropdownlist in gridview using 


In Previous posts I explained clearly how to implement ajax cascading dropdownlist using  and lot of articles regarding
Gridview. Now I will explain how to implement cascading dropdown list in gridview using Here I am using previous implemented article ajax cascading dropdownlist in to bind data to dropdownlists. 

After that I am binding the data to gridview for that first design table in database and give name UserInfomation

Int(set identity property=true)

After completion table creation add ajax reference to your application because here I am using ajax cascading dropdownlists bind to gridview and design your aspx page like this

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
<title>Cascading Dropdownlist Sample</title>
<form id="form1" runat="server">
<ajax:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"/>
<asp:GridView runat="server" ID="gvdetails" DataSourceID="dsdetails" AllowPaging="true" PageSize="10" AutoGenerateColumns="false" ShowFooter="true">
<RowStyle BackColor="#EFF3FB" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
<asp:TemplateField HeaderText="UserId">
<asp:Label ID="lblUserId" runat="server" Text='<%#Eval("UserId") %>'/>
<asp:TemplateField HeaderText="UserName">
<asp:Label ID="lblUserName" runat="server" Text='<%#Eval("UserName") %>'/>
<asp:DropDownList ID="ddlCountry" runat="server"></asp:DropDownList>
<ajax:CascadingDropDown ID="CountryCascading" runat="server" Category="Country" TargetControlID="ddlCountry" LoadingText="Loading Countries..." PromptText="Select Country" ServiceMethod="BindCountrydropdown" ServicePath="DropdownWebService.asmx">
<asp:TemplateField HeaderText="LastName">
<asp:Label ID="lblLastName" runat="server" Text='<%#Eval("LastName") %>'/>
<asp:DropDownList ID="ddlState" runat="server"></asp:DropDownList>
<ajax:CascadingDropDown ID="StateCascading" runat="server" Category="State" TargetControlID="ddlState" ParentControlID="ddlCountry" LoadingText="Loading States..." PromptText="Select State" ServiceMethod="BindStatedropdown" ServicePath="DropdownWebService.asmx">
<asp:TemplateField HeaderText="Location">
<asp:Label ID="lblLocation" runat="server" Text='<%#Eval("Location") %>'/>
<asp:DropDownList ID="ddlregion" runat="server"></asp:DropDownList>
<ajax:CascadingDropDown ID="RegionCascading" runat="server" Category="Region" TargetControlID="ddlregion" ParentControlID="ddlState" LoadingText="Loading Cities..." PromptText="select" ServiceMethod="BindRegiondropdown" ServicePath="DropdownWebService.asmx">
<asp:SqlDataSource ID="dsdetails" runat="server" ConnectionString="<%$ConnectionStrings:dbconnection %>"
SelectCommand="select * from UserInformation"/>
If you observe above code I used ajax cascading dropdownlist to bind in gridview. To bind data to dropdownlist and data tables design check this post ajax cascading dropdownlist using .After completion of bind data to dropdownlists use above code to place dropdownlist in gridview and bind data to gridview if you have any doubts just download the attached code to and check the details.

Here don’t forgot to set the connection string in web.config file here I am getting database connection from web.config file for that reason you need to set the connectionstring in web.config file like this

<add name="dbconnection" connectionString="Data Source=SureshDasari;Integrated Security=true;Initial Catalog=MySampleDB"/>

Download sample code attached

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest,, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email


Anonymous said...

Hi Suresh,
If the gridview initially does not have any data or is not binded to datasource but if we need some dropdownlists in such gridview. Should we have empty data template? I am confused what to do. I also have to populate the dropdownlist

Initially the gridview will have just 1 row with 4 dropdownlists which are populated. How to do this?

Suresh Dasari said...

i think that feature available in 4.0 version except that version we don't have any option like empty data template. we need to write custom code to display gridview even if that doesn't contain any data check below post

mariammalswe said...


Anonymous said...

Hello sir,
I am getting method error 500 rply

Unknown said...

hi friend i need 1 textbox1 ajax autocomplete, on select suggestion my textbox2 and textbox3 automatically display corresponding field the database table,,,, microsoft sql server, ajax(asmx web service)

ranvijay said...

please provide your database backup

Janu said...

please tel me how to covert date into weekday and i want to display that date into gridview.

Unknown said...

Dear sir in my gridview i have 3 dropdown list country
state and city when i change country according to change state and city..
pls help me

Anonymous said...

how can we do the same without using ajax

Unknown said...

i want add a new row ????

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.