gpt4 book ai didi

c# - SelectedValue 无效,因为它不存在于项目列表中

转载 作者:太空狗 更新时间:2023-10-30 01:08:39 29 4
gpt4 key购买 nike

这是我得到的错误:

ddlRankEdit' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value

我有一个带有多个下拉列表的表单,这些下拉列表嵌套在默认设置为不可见的面板中。当用户从单独的列表框中选择记录时,所选索引更改事件将面板设置为可见并进行数据调用。那是错误发生的时候。看下面的代码,我在停顿的地方添加了 XXX。

<asp:DropDownList runat="server" ID="ddlRankEdit" CssClass="txtfield" DataSourceID="ODCRanks"
DataTextField="Rank" DataValueField="ID" AppendDataBoundItems="True">
<asp:ListItem Text="--- Select a Rank ---" Value="-1" />
</asp:DropDownList>
<asp:ObjectDataSource ID="ODCRanks" runat="server"
OldValuesParameterFormatString="original_{0}" SelectMethod="GetRanks"
TypeName="RanksTableAdapters.RankTableAdapter"></asp:ObjectDataSource>

protected void lboxManageMembers_SelectedIndexChanged(object sender, EventArgs e)
{
pnlReviewMemberDetails.Visible = false;
pnlUnlockUserAccount.Visible = false;
pnlAdmins.Visible = false;
pnlCreateAdmins.Visible = false;
lblNote.Visible = false;
pnlManageMenbers.Visible = true;

MembershipUser user = Membership.GetUser();
DataSetTableAdapters.MemberInfoTableAdapter da = new DataSetTableAdapters.MemberInfoTableAdapter();

Guid _memberId = Guid.Empty;
_memberId = new Guid(lbxManageMembers.SelectedValue);
DataSet.MemberInfoDataTable dt = da.GetMember(_memberId);
if (dt.Rows.Count == 1)
{
DataSet.MemberInfoRow mr = dt[0];

XXX ddlRankEdit.SelectedValue = Convert.ToString(mr.rankid);
XXX ddlPatrolEdit.SelectedValue = Convert.ToString(mr.patrolid);
XXX ddlPositionEdit.SelectedValue = Convert.ToString(mr.bsaposid);

txtFirstNameEdit.Text = mr.firstname;
txtLastNameEdit.Text = mr.lastname;
txtEmailEdit.Text = user.Email;
txtAddressEdit.Text = mr.address;
txtPhoneEdit.Text = mr.phone;
txtCellPhoneEdit.Text = mr.altphone;
txtAltEmailEdit.Text = mr.altemail;

txtMotherFirstNameEdit.Text = mr.parentfn;
txtMotherLastNameEdit.Text = mr.parentln;
txtMotherWorkPhoneEdit.Text = mr.parentworkphone;
txtMotheHomePhoneEdit.Text = mr.parentworkphone;
txtMotherCellkPhoneEdit.Text = mr.parentscellphone;
txtMotherTwitterEdit.Text = mr.parenttwitter;
txtMotherEmailEdit.Text = mr.parentemail;
txtMotherAltEmailEdit.Text = mr.parentemailalt;

txtFatherFirstNameEdit.Text = mr.parent2fn;
txtFatherLastNameEdit.Text = mr.parent2ln;
txtFatherWorkPhoneEdit.Text = mr.parent2workphone;
txtFatherHomePhoneEdit.Text = mr.parent2workphone;
txtFatherCellPhoneEdit.Text = mr.parent2cellphone;
txtFatherTwitterEdit.Text = mr.parent2twitter;
txtFatherEmailEdit.Text = mr.parent2email;
txtFatherAltEmailEdit.Text = mr.parent2emailalt;
}

}

最佳答案

错误消息准确地告诉您发生了什么:例如存储在 mr.rankid 中的值不在下拉列表中。

您需要确定下拉列表是否包含正确的值,或者您尝试分配的值是否不存在于可用值列表中。

更新

由于似乎是包含面板的可见性导致了问题,因此最好使用 CSS 隐藏面板而不是将 Visible 属性设置为 false,这将阻止它渲染到页面。

这可以在代码隐藏中使用类似于以下的代码来完成:

Panel1.Style.Add(HtmlTextWriterStyle.Visibility, "Hidden");
Panel1.Style.Add(HtmlTextWriterStyle.Display, "None");

关于c# - SelectedValue 无效,因为它不存在于项目列表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8865140/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com