I am beginner in asp.net. I have two dropdownliastbox one Department and another is Employee. I want to poppulate all employee on
ddlemployee having on the selected department in ddlDepartment. I have selected 'Management' department, then seconed dropdown should poppulate all the emplyees under management. I have given the code below.
polachan
Member
29 Points
241 Posts
To bind dropdownlistbox depends on tha data on another dropdownlist box
Dec 21, 2012 07:17 AM|LINK
I am beginner in asp.net. I have two dropdownliastbox one Department and another is Employee. I want to poppulate all employee on
ddlemployee having on the selected department in ddlDepartment. I have selected 'Management' department, then seconed dropdown should poppulate all the emplyees under management. I have given the code below.
With Thanks
Pol
private void Department() { Employee objDepartment = new Employee(); ddlDepartment.DataSource = objDepartment.DisplaySubjects().Tables[0]; ddlDepartment.DataValueField = "Department"; ddlSubjects.DataBind(); } private void Employees() { Employee objEmployees = new Employee(); ddlEmployee.DataSource = objEmployees.DisplayTopics(value from ddlDepartment ).Tables[0]; ddlEmployee.DataValueField = "Employees"; ddlEmployee.DataBind(); }sameer_khanj...
Contributor
7046 Points
1376 Posts
Re: To bind dropdownlistbox depends on tha data on another dropdownlist box
Dec 21, 2012 07:41 AM|LINK
private void Department() { Employee objDepartment = new Employee(); ddlDepartment.DataSource = objDepartment.DisplaySubjects().Tables[0]; ddlDepartment.DataValueField = "Department"; ddlSubjects.DataBind(); } private void Employees(string DepartmentName ) { Employee objEmployees = new Employee(); ddlEmployee.DataSource = objEmployees.DisplayTopics(DepartmentName).Tables[0]; ddlEmployee.DataValueField = "Employees"; ddlEmployee.DataBind(); } protected void ddlDepartment_SelectedIndexChanged(object sender, EventArgs e) { string DepartmentName = ddlDepartment.SelectedValue.ToString(); Employees(DepartmentName); } add property in ddlDepartment dropdown in aspx page under SelectedIndexChanged="ddlDepartment_SelectedIndexChanged" AutoPostBack='True'sameer.khanjit@gmail.com
View Blog
Click "Mark as Answer" on the post that helped you.
oned_gk
All-Star
30915 Points
6326 Posts
Re: To bind dropdownlistbox depends on tha data on another dropdownlist box
Dec 21, 2012 09:53 AM|LINK
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="Department" DataValueField="ID"> </asp:DropDownList> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT [ID], [Department] FROM [DepartmentTable] ORDER BY [Department]"> </asp:SqlDataSource><asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="SqlDataSource2" DataTextField="Employee" DataValueField="ID"> </asp:DropDownList> <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT [Employee], [ID] FROM [EmployeeTable] WHERE ([Dep_ID] = @Dep_ID) ORDER BY [Employee]"> <SelectParameters> <asp:ControlParameter ControlID="DropDownList1" Name="Dep_ID" PropertyName="SelectedValue" Type="Int32" /> </SelectParameters> </asp:SqlDataSource>