DropDownList问题需要帮助!! [英] DropDownList Problem Need Help!!

查看:45
本文介绍了DropDownList问题需要帮助!!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码中出现了一个错误:SchoolReports.DropDownListCFY1和SchoolReports.DropDownListCFY1()之间出现错误歧义。我想要做的是我有两个数据绑定到sqldatasource的下拉列表。当我在第一个ddl中选择一个学校的名字时,我希望第二个只显示与该学校匹配的年份。到目前为止,这是行不通的。有人可以帮助我,因为我觉得我被卡住了。









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.




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();

推荐答案



1)你创建了一个方法与控件DropDownListCFY1同名并且编译器很混乱,这很有意义。



2)你试图使用void通过在调用时添加括号来返回值而不将其作为方法引用的方法。



我怀疑它是第一个:所以更改你的名字方法更合理,不要忘记改变你真正想要调用它的引用。手动更改名称 - 不要依赖VS来执行此操作。由于您拥有相同名称的控件,它可能至少会更改一些错误的名称!
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!


这篇关于DropDownList问题需要帮助!!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆