protected void Page_Load(object sender, EventArgs e)
    {
        string query = "SELECT staffid,firstname,lastname,dno,street,city,zipcode FROM dbo.house";

        if (!IsPostBack)
        {
            LBNotify.Items.Add("Delhi");
            LBNotify.Items.Add("Chennai");
            LBNotify.Items.Add("Chandigarh");

            try
            {
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    using (SqlCommand cmd = new SqlCommand(query, connection))
                    {
                        connection.Open();
                        using (SqlDataAdapter adapter = new SqlDataAdapter(query, connection))
                        {
                            adapter.Fill(ds);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Response.Write("\n Error: " + ex);
            }

            try
            {
                DDLStaffId.DataSource     = ds;
                DDLStaffId.DataTextField  = "staffid";
                DDLStaffId.DataValueField = "staffid";
                DDLStaffId.DataBind();

                /*LBNotify.DataSource = ds;
                 * LBNotify.DataTextField = "city";
                 * LBNotify.DataValueField = "city";
                 * LBNotify.DataBind();*/
            }

            catch (Exception ex)
            {
                Response.Write("\n Data Error: " + ex);
            }
        }
    }
    protected void DDLStaffId_SelectedIndexChanged(object sender, EventArgs e)
    {
        //lbl_Display.Text += LBNotify.SelectedItem.Value.ToString();
        DataSet ds = new DataSet();
        string  connectionString = @"Data Source=(localdb)\mssqllocaldb;Initial Catalog=master;Integrated Security=True";

        try
        {
            string query = "SELECT staffid,firstname,lastname,dno,street,city,zipcode FROM dbo.house";
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                using (SqlCommand cmd = new SqlCommand(query, connection))
                {
                    connection.Open();
                    using (SqlDataAdapter adapter = new SqlDataAdapter(query, connection))
                    {
                        adapter.Fill(ds);
                    }
                }
            }
        }
        catch (Exception ex)
        {
            Response.Write("\n Error: " + ex);
        }

        try
        {
            DDLStaffId.DataSource     = ds;
            DDLStaffId.DataTextField  = "staffid";
            DDLStaffId.DataValueField = "staffid";
            DDLStaffId.DataBind();

            /*
             * LBNotify.DataSource = ds;
             * LBNotify.DataTextField = "city";
             * LBNotify.DataValueField = "city";
             * LBNotify.DataBind();*/
        }

        catch (Exception ex)
        {
            Response.Write("\n Data Error: " + ex);
        }


        try
        {
            //for (int i= 0;i < ds.Tables[0].Rows.Count;++i)
            //{

            lbl_Display.Text += ds.Tables[0].Rows[Convert.ToInt32(DDLStaffId.SelectedIndex)]["staffid"].ToString() + "<br/>" + ds.Tables[0].Rows[Convert.ToInt32(DDLStaffId.SelectedIndex)]["firstname"].ToString() + "<br/>" + ds.Tables[0].Rows[Convert.ToInt32(DDLStaffId.SelectedIndex)]["lastname"].ToString() + "<br/>" + ds.Tables[0].Rows[Convert.ToInt32(DDLStaffId.SelectedIndex)]["dno"].ToString() + "<br/>" + ds.Tables[0].Rows[Convert.ToInt32(DDLStaffId.SelectedIndex)]["street"].ToString() + "<br/>" + ds.Tables[0].Rows[Convert.ToInt32(DDLStaffId.SelectedIndex)]["city"].ToString() + "<br/>" + ds.Tables[0].Rows[Convert.ToInt32(DDLStaffId.SelectedIndex)]["zipcode"].ToString() + "<br/>";

            //}
            //Response.Write("\n Selected");
        }
        catch (Exception ex)
        {
            Response.Write("\nDataRow Error in foreach: " + ex);
        }
    }