5
Answers

Related DropDownlists

Ask a question
ToBe

ToBe

11y
893
1
Hi 

I have 3 related Dropdownlist in me Edit Form 

I'm using the code  below to bind the Dropdownlist but it will retrive the full list without the selected value saved  and if i'm making a selected statment it will just retrive the selected value.

the dropdownlist is linked to other one so if the Category been saved as "Art" the Subject should retrive the saved Item the user selected earlier with the rest items for update purpose .

private void BindDrp_CAT()
        {


           using (SqlConnection con = new SqlConnection(myconn))


            if (!IsPostBack)
            {


                SqlCommand com = new SqlCommand("select distinct Cat_name from tblCategory order by Cat_name ", con);


                 SqlDataReader dr;
                con.Open();


                Drp_CAT.Items.Clear();


                dr = com.ExecuteReader();
                while (dr.Read())
                {
                    Drp_CAT.Items.Add(new ListItem(dr[0].ToString()));
                   
                }
                con.Close();
               


            }
       
       
        }



Answers (5)