<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <asp:ScriptManager ID="scm" runat="server"></asp:ScriptManager> <table> <tr> <td> <asp:DropDownList ID="ddldepartment" runat="server" onselectedindexchanged="ddldepartment_SelectedIndexChanged" AutoPostBack="true"></asp:DropDownList> </td> </tr> <tr> <td> <asp:GridView ID="gv" runat="server" DataKeyNames="empid"></asp:GridView> </td> </tr> </table> </asp:Content>
public partial class GetDetailsbydropdown : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { CustomersBusiness cb = new CustomersBusiness(); if (!IsPostBack) { ddldepartment.DataSource = cb.GetDepartment(); ddldepartment.DataTextField = "departmentid"; ddldepartment.DataValueField = "departmentname"; ddldepartment.DataBind(); } } protected void ddldepartment_SelectedIndexChanged(object sender, EventArgs e) { CustomersBusiness cb=new CustomersBusiness(); Customers cs = new Customers(); cs.departmentid = Convert.ToInt32(ddldepartment.SelectedItem.Text); gv.DataSource = cb.GetEmployeebyDepartment(cs); gv.DataBind(); } } in businesslogic.cs public List<customers> GetEmployeebyDepartment(Customers cs) { List<customers> lst = new List<customers>(); SqlConnection con = new SqlConnection(constring); con.Open(); string query = "select empid, empname, departmentid, joiningdate, locationid, salary, jobid, isworking where departmentid=@departmentid"; cmd = new SqlCommand(query, con); dr = cmd.ExecuteReader(); if (dr.HasRows) { while (dr.Read()) { Customers cst = new Customers(); cst.employeeid = (int)dr[0]; cst.empname = (string)dr[1]; cst.departmentid = (int)dr[2]; cst.joiningdate = (DateTime)dr[3]; cst.locationid = (int)dr[4]; cst.salary = (int)dr[5]; cst.jobid = (int)dr[6]; cst.isworking = (Boolean)dr[7]; lst.Add(cst); } } return lst; }
cmd.Parameters.AddWithValue("@departmentid", deptid);
string query = "select empid, empname, departmentid, joiningdate, locationid, salary, jobid, isworking where departmentid="+cs.departmentid;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)