Click here to Skip to main content
15,886,693 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi I have web page in asp.net and db sql server with id_field,year_field,price_field in my web page there are a dropdownlist for select a special year and a label for display special price I want when selected value.selected then prise showon in label
Hi I have 4 DropDownList in asp.net vs c# and in app_code I have this code to fill ddl from databas:

public void fillddl(DropDownList ddl, string tablename, string textfieldname, string valuefieldname)
   {
       SqlConnection scon = new SqlConnection(cstr);
       scon.Open();
       string selectstr = string.Format("SELECT {0},{1} FROM {2}",
 
                                        textfieldname,
                                        valuefieldname,
                                        tablename);
       SqlDataAdapter sda = new SqlDataAdapter(selectstr,scon );
       DataSet ds = new DataSet();
       sda.Fill(ds);
       ddl.DataSource = ds;
       ddl.DataTextField = textfieldname;
       ddl.DataValueField = valuefieldname;
       ddl.DataBind();
       scon.Close();
 
   }

and in page_load I have this code :
if (!Page.IsPostBack)
        {
            dbmanager dbm = new dbmanager();
            dbm.fillddl(DropDownList1, "my_tbl", "year", "price");
            dbm.fillddl(DropDownList2, "my_tbl", "year", "price");
            dbm.fillddl(DropDownList3, "my_tbl", "year", "price");
            dbm.fillddl(DropDownList4, "my_tbl", "year", "price");
        }

and this code:
C#
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
   {
       Label1.Text = DropDownList1.SelectedValue.ToString();
   }
   protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
   {
       Label2.Text = DropDownList2.SelectedValue.ToString();
   }
   protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
   {
       Label3.Text = DropDownList3.SelectedValue.ToString();
   }
    protected void DropDownList4_SelectedIndexChanged(object sender, EventArgs e)
   {
       Label4.Text = DropDownList4.SelectedValue.ToString();
   }




suppose that year_field in my ddl values are:
2012
2013
2014
2015
and price_value:
100
200
100
400
the problem is that when I select 2012 or 2014 ( the price of them are same and equal) the ddl selected does not changed. but for other year (which theire price are different)ddlselected value changed and work good.
please help me!
Posted
Updated 17-Nov-15 1:46am
v3
Comments
Richard Deeming 16-Nov-15 15:03pm    
REPOST
You have already posted this question:
http://www.codeproject.com/Questions/1056403/why-selected-specific-Items-of-DropDownList-does-n[^]

If you want to update your question, use the "Improve question" button. DO NOT post a new copy of the same question.
rezaeti 16-Nov-15 21:44pm    
is there any one to answer me ?
Krunal Rohit 17-Nov-15 8:43am    
Uhh, Reposting won't get you the answer.

-KR
Gyaneswar kumar 18-Nov-15 1:35am    
use 'ispostback=true' against the required dropdown control then populate those dependent control by selected value/item.l

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