Click here to Skip to main content
15,911,139 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I dont know this is possible or not in asp.net c#.
Here is my html code that contains 2 fields drop down list.
if i select any item from 1st drop down and on that basis 2nd field does have the items to select. Is this possible in pure C# code as we do in asp controls.
Thanks.
<div class="form-group">
                                       <select class="custom-select custom-select-width100 productbrand" name="product1brand">
                                           <option value="">Brand</option>
                                           <option value="Brand 1">Brand 1</option>
                                           <option value="Brand 2">Brand 2</option>
                                       </select>
                                       <label id="product1brand-error" class="error" for="product1brand"></label>
                                   </div>
                                   <div class="form-group">
                                       <select class="custom-select custom-select-width100 productproduct" name="product1product">
                                           <option value="">Product</option>
                                           <option value="Product 1">Product 1</option>
                                           <option value="Product 2">Product 2</option>
                                       </select>
                                       <label id="product1product-error" class="error" for="product1product"></label>
                                   </div>
                               </div>


What I have tried:

this is code to bind data to drop down list in 1st field.
and i have 2 database table in which 1st have primary key and 2nd table has its reference.
protected void Page_Load(object sender, EventArgs e)
       {
           if (!IsPostBack)
           {
               SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DBcon"].ConnectionString);
               con.Open();
               string QueryString = "select * from Brand";

               SqlDataAdapter myCommand = new SqlDataAdapter(QueryString, con);
               DataSet ds = new DataSet();
               myCommand.Fill(ds);

               product1brand.DataSource = ds;
               product1brand.DataTextField = "Brand_Name";
               product1brand.DataValueField = "Brand_Id";
               product1brand.DataBind();
           }
Posted
Comments
Dotnet_Dotnet 29-Nov-17 10:34am    
product1brand.DataSource = ds.tables[0];
F-ES Sitecore 29-Nov-17 10:36am    
Is there a reason you don't just use server-side controls? Even a select element with runat=server? What you want to do is possible but I don't see the point in overcomplicating things when using server side controls will solve all of your issues.
Vikrant_saini 29-Nov-17 10:49am    
I did this using runat=server but i dont get what i want in select field product1product.
F-ES Sitecore 29-Nov-17 11:00am    
You're better asking how you can fix the issue you have with run=server than asking how to do it without as it all gets quite complicated and needlessly so, I'm sure your original issue can be solved.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900