Click here to Skip to main content
15,885,032 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
Hello. I have three DropDownList on a form. One is school names and the other two are years. I have the DropDownList that are years to populate two textboxes when a year is selected. I also have all three DropDownList databound. The year DropDownList has populated with all the years from my database. I was trying to get it to only populate with the years that match the school. Next what I am trying to do is to select a school's year from DropDownList year to populate the textboxes. The population works but when I select a different year it resets back to the first year that was selected. What am I doing wrong? Can someone help me?!!!

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();
    }
    protected void DropDownListCFY2_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 = " + DropDownListCFY2.SelectedValue.ToString(), con);

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

            

        }
        dr.Close();
        con.Close();
Posted
Updated 5-Sep-13 6:48am
v2
Comments
PIEBALDconsult 5-Sep-13 12:09pm    
What does that have to do with Data Definition Language?
Computer Wiz99 5-Sep-13 12:12pm    
I'm sorry I wasn't talking about DDL as being Data Definition Language. I should have put ddl as in DropDownList.
Richard MacCutchan 5-Sep-13 12:13pm    
Then use proper words, don't assume people can understand your abbreviations.
TryAndSucceed 5-Sep-13 17:22pm    
Well, all I see is SelectedIndexChanged events. Where are you populating dropdowns? May be when you do the postback, you are setting the dropdowns to initial values.
Computer Wiz99 5-Sep-13 18:29pm    
Sorry it took me so long to reply. I am populating the DropDownList from SQLDataSource.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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