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:
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!