using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SqlClient; using System.Data; using System.Data.OleDb; using System.Configuration; public partial class Forms_Master_Forms_Temporary_duty_form : System.Web.UI.Page { SqlConnection conn = new SqlConnection("Server=SOFTDEV1; Database=ADE_2903_SOFTDEV; Integrated security = true"); protected void Page_Load(object sender, EventArgs e) { DropDownList7.Visible = false; if (!IsPostBack) { Getdata();//adding the division to the dropdown box } } /* Adding The contents to the Division DropDown List */ private void Getdata() { SqlCommand cmd = new SqlCommand("SELECT DivisionID, DivShort FROM M_Division ORDER BY DivShort", conn); DataSet objDs = new DataSet(); SqlDataAdapter sd = new SqlDataAdapter(cmd); conn.Open(); sd.Fill(objDs); conn.Close(); if (objDs.Tables[0].Rows.Count > 0) { ddlgroup.DataSource = objDs.Tables[0]; ddlgroup.DataTextField = "DivShort"; ddlgroup.DataValueField = "DivisionID"; ddlgroup.DataBind(); ddlgroup.Items.Insert(0, "--Select--"); } } /*Adding the names to the Name DropDownList based on the selected division from Division Drop Down List*/ private void FillName(int divisionID) { SqlCommand cmd = new SqlCommand("SELECT DivisionID, EmpName FROM M_Emp_Personal WHERE DivisionID =@DivisionID AND IsActive=1 ORDER BY EmpName", conn); cmd.Parameters.AddWithValue("@DivisionID", divisionID); DataSet objDs = new DataSet(); SqlDataAdapter sd = new SqlDataAdapter(cmd); conn.Open(); sd.Fill(objDs); conn.Close(); if (objDs.Tables[0].Rows.Count > 0) { ddlname.DataSource = objDs.Tables[0]; ddlname.DataTextField = "EmpName"; ddlname.DataValueField = "DivisionID"; ddlname.DataBind(); ddlname.Items.Insert(0, "--Select--"); } } /*Selecting the division present in the dropdownlist*/ protected void ddlgroup_SelectedIndexChanged1(object sender, EventArgs e) { int DivisionID = Convert.ToInt32(ddlgroup.SelectedValue.ToString()); FillName(DivisionID); ddlname.SelectedIndex = 0; } /*Selecting the name present in the dropdownlist*/ protected void ddlname_SelectedIndexChanged(object sender, EventArgs e) { int DesingID = Convert.ToInt32(ddlgroup.SelectedValue.ToString()); FillDesig(DesingID); } private void FillDesig(int desingID) { SqlCommand cmd = new SqlCommand("Select M_Designation.DesigLong,M_Emp_Personal.EmpName From M_Designation inner join M_Emp_Personal on M_Designation.DesigID=M_Emp_Personal.DesigID", conn); cmd.Parameters.AddWithValue("@DesigID", desingID); conn.Open(); lbldes.Text = cmd.ExecuteScalar().ToString(); conn.Close(); } } The ASP.NET code is <pre lang="HTML"> <asp:DropDownList ID="ddlgroup" runat="server" style="z-index: 1; left: 118px; top: 148px; position: absolute; height: -5px;" AutoPostBack="True" onselectedindexchanged="ddlgroup_SelectedIndexChanged1"> </asp:DropDownList> <asp:DropDownList ID="ddlname" runat="server" style="z-index: 1; left: 332px; top: 147px; position: absolute; height: 35px; width: 117px;" onselectedindexchanged="ddlname_SelectedIndexChanged" AutoPostBack="True"> </asp:DropDownList> <table style="width: 85%; removed 207px; removed 14px; removed: absolute; height: 593px;"> <tr> <td class="style5"> 2.</td> <td class="style7"> DESIGNATION</td> <td colspan="3"> <asp:Label ID="lbldes" runat="server" Text="Label"></asp:Label> </td> </tr>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)