Skip to content

Related DropDownlists

ToBe

Asked May 26, 2013, 12:45 AM EDT5 answers
Share
LinkedInX
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();
               


            }
       
       
        }

5 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    hi
    if ur coding the edit form then first all the dropdown list with the data which they should contain in page load. then when u bind the other value which where entered by the user in that  part of code just write below line

    Drp_CAT.selecteditem.text="classobj.property"
    (the object of the class and name of the property)

    this will show the values which was submitted at first and will give other option for update.

    if u dont get the line then please do share that page and the class library .cs file if ur using  any one
    0
  • 0
    Hi Rohit

    thanks for reply 

    didn't get u sorry where should i Put this : Drp_CAT.selecteditem.text="classobj.property"


      in my up code ?
    0
  • 0
    hi
    are u using the UserInfo.cs file which contain the variable and property.
    and in edit.aspx.cs make 2 public method first two fill the drop down like BindDropDown()
    after this 2nd method to bind the user filled information in to page like userBind()
    and in the 2nd method write those line
    create object of userInfo.cs like objuser
    Drp_CAT.selectedItem.Text=objuser.cat //proprty_name
    regarding catagory
    0
  • 0
    Hi again No I'm not using UserInfo.cs
    0
  • 0
    then how are u getting the data from database?

    Can u share the app and write the page name on which u want the coding so i can help u out
    0