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();
}
}
Rohit Kapdi19 pointsPosted May 26, 2013, 8:37 PM EDT
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
ToBe99 pointsPosted May 26, 2013, 11:19 PM EDT
thanks for reply
didn't get u sorry where should i Put this : Drp_CAT.selecteditem.text="classobj.property"
in my up code ?
Rohit Kapdi19 pointsPosted May 27, 2013, 2:21 AM EDT
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
ToBe99 pointsPosted May 27, 2013, 11:27 PM EDT
Rohit Kapdi19 pointsPosted May 29, 2013, 11:17 PM EDT
Can u share the app and write the page name on which u want the coding so i can help u out