Click here to Skip to main content
15,914,066 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am having an error come up in my code that says: Error Ambiguity between 'SchoolReports.DropDownListCFY1' and 'SchoolReports.DropDownListCFY1()'. What I am trying to do is that 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();

            int a = Convert.ToInt32(TextBoxTA1.Text);
            int b = Convert.ToInt32(TextBoxTL1.Text);
            TextBoxTNA1.Text = Convert.ToString(a - b);



        }
        dr.Close();
        con.Close();
Posted
Updated 6-Sep-13 5:12am
v2
Comments
ZurdoDev 6-Sep-13 9:55am    
Name your control something else. It is a conflict.
Computer Wiz99 6-Sep-13 10:00am    
Ok. In my code I have a blue line under the DropDownListCFY1() that is part of protected void. And I have a red line under DropDownListCFY1 that is part of the .SelectedValue.ToString(). Which one should be changed?
ZurdoDev 6-Sep-13 10:05am    
Doesn't matter.
Computer Wiz99 6-Sep-13 10:10am    
If I change the name of the control then my code will not work. So how am I going to change the name of the control that I want to control?
ZurdoDev 6-Sep-13 10:20am    
Of course you would also have to change the name of it anywhere referenced.

1 solution

Either
1) You have created a method with the same name as a control "DropDownListCFY1" and the compiler is confused, which would make a lot of sense.
Or
2) You have tried to use a void method to return a value without referencing it as a method by adding the brackets when you call it.

I suspect it is the first one: so change the name of your method to something more sensible and don't forget to change the references where you actually want to call it as well. Change the name manually - do not rely on VS to do it. As you have a control of the same name, it will probably change at least some of the wrong names!
 
Share this answer
 
Comments
Computer Wiz99 6-Sep-13 10:15am    
OriginalGriff, Can you show me? I will change the first one but how can I get my dropdownlist that has years databound to it to only shw the years for the school that is selected? Right now the ddl that has years databound to it has all of the years in it. I just want the years that matches with the school to show when the school is selected in the first ddl.

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