I have three drop downs -bounded with object datasources,
by default each drop down shows all countries (as i changed in prerender -st=null), cites and distt.
i need -When user select country only related cities should show under city dropdown. and when user select city-only distt related to city show up --How to do that
Here's the code
STATE:
<asp:DropDownList ID="ddlSt" runat="server"
DataSourceID="OdsState"
DataTextField="STATE_COUNTRY_NAME"
DataValueField="STATE_COUNTRY_CODE"
AutoPostBack="True" OnInit="ddlst_Init"
onselectedindexchanged="ddlSt_SelectedIndexChanged" AppendDataBoundItems="true">
<asp:ListItem Text="" Value="0"></asp:ListItem>
</asp:DropDownList>
<asp:ObjectDataSource ID="OdsState" runat="server"
OldValuesParameterFormatString="original_{0}" SelectMethod="GetData"
TypeName="stateTableAdapters.STATE_COUNTRYTableAdapter">
<SelectParameters>
<asp:ControlParameter ControlID="ddlyr" Name="FromYear"
PropertyName="SelectedValue" Type="Decimal" DefaultValue="null" />
<asp:ControlParameter ControlID="ddlTo" Name="ToYear"
PropertyName="SelectedValue" Type="Decimal" />
<asp:ControlParameter ControlID="RBl1" Name="mytype"
PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="SrcCty" runat="server"
OldValuesParameterFormatString="original_{0}" SelectMethod="GetData"
TypeName="stateTableAdapters.CityTableAdapter">
<SelectParameters>
<asp:ControlParameter ControlID="ddlSt" Name="MyState"
PropertyName="SelectedValue" Type="String" DefaultValue="null" />
<asp:ControlParameter ControlID="RBl1" Name="mytype"
PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="ddlyr" Name="FromYear"
PropertyName="SelectedValue" Type="Decimal" />
<asp:ControlParameter ControlID="ddlTo" Name="ToYear"
PropertyName="SelectedValue" Type="Decimal" />
</SelectParameters>
</asp:ObjectDataSource>
CITY:
<asp:DropDownList ID="ddlCity" runat="server" DataSourceID="SrcCty"
DataTextField="CITY" DataValueField="STATE_COUNTRY_CODE" OnInit="ddlcity_Init" AppendDataBoundItems="true" >
<asp:ListItem Text=" " Value="0"></asp:ListItem>
</asp:DropDownList>
<asp:ObjectDataSource ID="SrcDistt" runat="server"
OldValuesParameterFormatString="original_{0}" SelectMethod="GetData"
TypeName="stateTableAdapters.DisttTableAdapter">
<SelectParameters>
<asp:ControlParameter ControlID="RBl1" DefaultValue=""G""
Name="mytype" PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="ddlSt" Name="myState"
PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="ddlyr" Name="FromYear"
PropertyName="SelectedValue" Type="Decimal" />
<asp:ControlParameter ControlID="ddlTo" DefaultValue="" ""
Name="ToYear" PropertyName="SelectedValue" Type="Decimal" />
<asp:ControlParameter ControlID="ddlCity" DefaultValue="null" Name="mycity"
PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
Cong.Dist:
<asp:DropDownList ID="ddlCongDistt" runat="server" Width="100" AutoPostBack="true"
DataSourceID="SrcDistt" DataTextField="congrsnl_district_code"
onselectedindexchanged="ddlCongDistt_SelectedIndexChanged" AppendDataBoundItems="true" >
<asp:ListItem Text="" Value="0"></asp:ListItem>
</asp:DropDownList> <br /> <br/>In c#
and in C#
protected void Page_Prerender(Object sender, EventArgs e)
{
if (!IsPostBack)
{
OdsState.SelectParameters["ToYear"].DefaultValue = null;
SrcCty.SelectParameters["myState"].DefaultValue = null;
SrcDistt.SelectParameters["myState"].DefaultValue = null;
SrcDistt.SelectParameters["mycity"].DefaultValue = null;
}
}
protected void RBl1_SelectedIndexChanged(object sender, EventArgs e)
{
MakeSQL();
}
protected void ddlst_Init(object sender, EventArgs e)
{
ddlSt.Items.Insert(0, new ListItem("--", string.Empty));
}
protected void ddlSt_SelectedIndexChanged(object sender, EventArgs e)
{
sSQL += "AND STATE_COUNTRY_CODE='" + ddlSt.SelectedValue.ToString() + "'";
MakeSQL();
}
protected void ddlcity_Init(object sender, EventArgs e)
{
ddlCity.Items.Insert(0, new ListItem("---", string.Empty));
}
protected void ddlCity_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddlSt.SelectedIndex >= 0)
{
SrcCty.SelectParameters["myState"].DefaultValue = ddlSt.SelectedValue;
}
sSQL += "AND CITY='" + ddlCity.SelectedValue.ToString() + "'";
lblmsg.Text = sSQL;
MakeSQL();
}
protected void ddlCongDistt_SelectedIndexChanged(object sender, EventArgs e)
{
sSQL += "AND congrsnl_district_code ='" + ddlCongDistt.SelectedValue.ToString() + "'";
MakeSQL();
}