相关疑难解决方法(0)

无法在DropDownList中选择多个项目

我有两个下拉列表和一个按钮.我在项目中使用了断点,一切正常.但是,一旦我退出按钮的功能,这就是我得到的错误:

无法在DropDownList中选择多个项目.

这是我按钮的代码:

 protected void Button1_Click(object sender, EventArgs e)
    {

        if (ddlPlayer1.SelectedItem.Value != "0" || ddlPlayer2.SelectedItem.Value != "0" && ddlPlayer1.SelectedItem.Value != ddlPlayer2.SelectedItem.Value)
        {
            lblPlayer1Score.Text = Repository.Instance.ReturnScore(ddlPlayer1.SelectedValue.ToString(), ddlPlayer2.SelectedValue.ToString()).Rows[0][0].ToString();
            lblPlayer2Score.Text = Repository.Instance.ReturnScore(ddlPlayer2.SelectedValue.ToString(), ddlPlayer1.SelectedValue.ToString()).Rows[0][0].ToString();


        }

        ddlPlayer1.DataBind();
        ddlPlayer2.DataBind();
    }
Run Code Online (Sandbox Code Playgroud)

我在这做错了什么?

.net c# asp.net

36
推荐指数
3
解决办法
6万
查看次数

DropDownList.Items.FindByValue()上的NullReferenceException

我希望有人可以帮我解决一个小小的谜团......

此代码正在生产中,并在那里工作.问题出现在我的localhost上(我正在测试我在发布到staging之前所做的更改). 这工作到2天前,我不知道它为什么会自发地停止工作.

(这是一个.NET 3.5 Web窗体应用程序)

我有一份可能已报告事件的"组织"列表.该列表从我的数据库中的Organization表填充.

<asp:DropDownList ID="Organizations" runat="server" Width="205" AutoPostBack="True" DataTextField="Name" DataValueField="Id"></asp:DropDownList>
Run Code Online (Sandbox Code Playgroud)

这是绑定列表的代码:

Organizations.DataSource = _service.ListOrganizations()
        .Where(o => o.IsDeleted == false && o.ReportedBy == true)
        .OrderBy(o => o.Name);
Organizations.DataBind();
Organizations.Items.Insert(0, new ListItem("Please make a selection", "-1"));
// Find the "VICTIM...." items
ListItem victim = Organizations.Items.FindByText("VICTIM");
ListItem guardian = Organizations.Items.FindByText("VICTIM'S PARENT/GUARDIAN");
ListItem child = Organizations.Items.FindByText("VICTIM'S SON/DAUGHTER");
ListItem partner = Organizations.Items.FindByText("VICTIM'S SPOUSE/DOMESTIC PARTNER");
ListItem unknown = Organizations.Items.FindByText("UNKNOWN");
// Move the "VICTIM...." items to the top of the list, under …
Run Code Online (Sandbox Code Playgroud)

c# asp.net nullreferenceexception

11
推荐指数
1
解决办法
4321
查看次数

标签 统计

asp.net ×2

c# ×2

.net ×1

nullreferenceexception ×1