Ankita Singh

Ankita Singh

  • NA
  • 159
  • 19.1k

cascading dropdown

Mar 6 2018 6:56 AM
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GetCourse();
}
}
private void GetCourse()
{
DataTable coursedt = new DataTable();
coursedt.Columns.Add("CourseId", typeof(int));
coursedt.Columns.Add("CourseName");
coursedt.Rows.Add(0, "select");
coursedt.Rows.Add(1, "B.Tech");
coursedt.Rows.Add(2, "Polytechnic");
coursedt.Rows.Add(3, "MBA");
Course.DataSource = coursedt;
Course.DataTextField = "CourseName";
Course.DataValueField = "CourseId";
Course.DataBind();
}
this code for bind data to paraent dropdownlist.....
protected void OnCourseChange(object sender, EventArgs e)
{
// ACan.AppendDataBoundItems = true;
if (int.Parse(Course.SelectedValue) > 0)
{
// divACan.Visible = true;
DataTable dt = new DataTable();
dt.Columns.Add("ACanId", typeof(int));
dt.Columns.Add("CourseId", typeof(int));
dt.Columns.Add("ACanName");
if (Course.SelectedValue == "1")
{
dt.Rows.Add(1, 1, "Appearing In Class 12th");
Labeltenper.Visible = true;
Labelyear10.Visible = true;
Labelpertwelth.Visible = true;
Labelyearof12th.Visible = true;
//Labelyearofgra.Visible = false;
//Labelgraper.Visible = false;
}
if (Course.SelectedValue == "2")
{
dt.Rows.Add(2, 2, "Appearing In Class 10th");
Labeltenper.Visible = true;
Labelyear10.Visible = true;
//Labelpertwelth.Visible = false;
//Labelyearof12th.Visible = false;
//Labelyearofgra.Visible = false;
//Labelgraper.Visible = false;
}
if (Course.SelectedValue == "3")
{
dt.Rows.Add(3, 3, "Appearing In Graduation");
Labeltenper.Visible = true;
Labelyear10.Visible = true;
Labelpertwelth.Visible = true;
Labelyearof12th.Visible = true;
Labelyearofgra.Visible = true;
Labelgraper.Visible = true;
}
ACan.DataSource = dt;
ACan.DataTextField = "ACanName";
ACan.DataValueField = "ACanId";
ACan.DataBind();
}
}
 
its OnSelectedIndexChanged code
 
<asp:DropDownList ID="Course" runat="server" class="slectbig" AutoPostBack="true" OnClientClick="return false;" OnSelectedIndexChanged="OnCourseChange">
</asp:DropDownList>
<asp:DropDownList ID="ACan" runat="server" class="slectbig" DataTextField="Select">
<asp:ListItem Value="0"> Select </asp:ListItem>
</asp:DropDownList>
 
here is 2 dropdown control...
 
my problem:- if i select 1st dropdown then bind data.... and select any item in this dropdown then page postback after postback data come in 2nd dropdown control.... wanna do that without postback cascading dropdown do work
 
thanks....

Answers (3)