Click here to Skip to main content
15,892,575 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friend, Please Help me,
I have two dropdownlists and two nested GridViews. In first dropdwnlist continents and second countries. I want to bound two GridView into GridView. In first GridView i want to States and second GridView i want fill District.
When i select continents in first dropdwnlist then second dropdwnlist fill that countries. When i select second dropdwnlist's countries, then how to fill nested GridView States and Districts. Can I do it in ASP.NET C#. Please Help me.
Posted
Updated 28-Jul-14 5:04am
v2

I guess there is no need to use GridView. One is dependent on other. So, you can use CascadingDropDown[^] for this type of work.

Example - Ajax Cascading Dropdownlist Sample with database using asp.net[^]
 
Share this answer
 
u can bind first gridview in usual way passing the coutry dropdown selected value to gridview bound. For the second gridview u hav to boud it in first gridview itembound event as tis

protected void grdState_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DataTable DT = new DataTable();
// U can set the StateId in Hidden Filed of State GridView and access it here.
HiddenField StateID = (HiddenField)e.Item.FindControl("HidStateId");
GridView grvTemplateinfo;
SqlDataADapter Sqlda=New SqlDataAdapter("Your cmd ","Connection");
Sqlda.Fill(DT);
grdDistrict = (GridView)e.Item.FindControl("grdDistrict");
if (DT.Rows.Count > 0)
{
grdDistrict.RowStyle.Wrap = true;
grdDistrict.DataSource = DT;
grdDistrict.DataBind();
}

}
}
Hope this helps
 
Share this answer
 
If you are not familiar with Ajax, You can use J query

https://github.com/dnasir/jquery-cascading-dropdown[^]
 
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