c# - problem in accessing data from sql in two drop down list at same time -


I have two drop-down lists in the web form. For both of them I used to bind the code to SQL I have done this but whenever I am trying to force the second drop down list with the same method..It is giving error .. I used the code:

  secured zero Page_load (Object Sender, EventArgs e) {If (Post! IsPostBack) {ddlPropertyType.AppendDataBoundItems = true; String strConnString = ConfigurationManager.ConnectionStrings ["conString"]. ConnectionString; String Structures = "Select ID, type property by property name"; SqlConnection con = new SqlConnection (strConnString); SqlCommand CMD = new SQL Commands (); Cmd.CommandType = CommandType.Text; Cmd.CommandText = strQuery; Cmd.Connection = con; Try {con.Open (); DdlPropertyType.DataSource = cmd.ExecuteReader (); DdlPropertyType.DataTextField = "Property Name"; DdlPropertyType.DataValueField = "ID"; DdlPropertyType.DataBind (); } Hold (Exceptional) {East; } Finally {con.Close (); Con.Dispose (); }}    

You want to create two dropdown lists with dependency between them. You need to enable autopost in the "Parents" dropdown list, add the changed event to it, and load your "child" dropdown list in the event.

You have a good example here:

Comments