Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have two dropdownlists that are databound to a sqldatasource. When I select a name of a school in the first ddl I would like the second to show only years that matches that school. So far this is not working. Can someone help me because I think I am stuck.

C#
protected void DropDownListSchools_SelectedIndexChanged(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
        con.Open();
 
        lblINST_ID.Text = DropDownListSchools.SelectedValue;
 

 

    }
    protected void DropDownListCFY1_SelectedIndexChanged(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
        con.Open();
        SqlCommand scmd = new SqlCommand("Select TOTASSETS, TOTLIABILITY from TableFIN where INST_ID = " + DropDownListCFY1.SelectedValue.ToString(), con);
       
        SqlDataReader dr = scmd.ExecuteReader();
        if (dr.Read())
        {
            TextBoxTA1.Text = dr["TOTASSETS"].ToString();
 
            TextBoxTL1.Text = dr["TOTLIABILITY"].ToString();
 
            
 
        }
        dr.Close();
        con.Close();
Posted

1 solution

1.Call the DropDownListCFY1 in DropDownListSchools_SelectedIndexChanged()

2.There is no need for DropDownListCFY1 SelectedIndexChanged event

3.set autopastback=true for DropDownListCFY1

protected void DropDownListSchools_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
con.Open();

lblINST_ID.Text = DropDownListSchools.SelectedValue;


DropDownListCFY1();

}
protected void DropDownListCFY1()
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
con.Open();
SqlCommand scmd = new SqlCommand("Select TOTASSETS, TOTLIABILITY from TableFIN where INST_ID = " + DropDownListCFY1.SelectedValue.ToString(), con);

SqlDataReader dr = scmd.ExecuteReader();
if (dr.Read())
{
TextBoxTA1.Text = dr["TOTASSETS"].ToString();

TextBoxTL1.Text = dr["TOTLIABILITY"].ToString();



}
dr.Close();
con.Close();
 
Share this answer
 
v2
Comments
Computer Wiz99 6-Sep-13 9:18am    
Jas24, I made the changes that you put up for me and I get an error: Ambiguity between 'SchoolReports.DropDownListCFY1' and 'SchoolReports.DropDownListCFY1()'. Why is this error happening?
Tom Marvolo Riddle 6-Sep-13 9:25am    
Sorry dude I have to log off now..

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