asp.net – 具有一个无效的SelectedValue,因为它在项目列表中不存在.你怎么调试?

前端之家收集整理的这篇文章主要介绍了asp.net – 具有一个无效的SelectedValue,因为它在项目列表中不存在.你怎么调试?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我遇到asp.net绑定到下拉列表的问题,我不知道如何调试.我在堆栈上查看了有关此问题的其他问题,但没有任何帮助.据我所知,它应该选择的“名称”在列表中.
<asp:DropDownList ID="dd1" runat="server" DataSourceID="ADataSource" DataTextField="Name" 
                                                    DataValueField="Name" SelectedValue='<%# Bind("Name") %>'   Width="255" 
                                                    AppendDataBoundItems="true" TabIndex="3"  Font-Size="small"  EnableViewState="true"    >
                                             <asp:ListItem Text="Select"  Value="" />
                                           </asp:DropDownList>

以下是错误

System.ArgumentOutOfRangeException was unhandled by user code
Message=’dd1′ has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value
Source=System.Web
ParamName=value
StackTrace:
at System.Web.UI.WebControls.ListControl.PerformDataBinding(IEnumerable
dataSource)
at System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e)
at System.Web.UI.WebControls.ListControl.PerformSelect()
at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
at System.Web.UI.Control.DataBindChildren()
at System.Web.UI.Control.DataBind(Boolean raiSEOnDataBinding)
at System.Web.UI.Control.DataBind()
at System.Web.UI.Control.DataBindChildren()
at System.Web.UI.Control.DataBind(Boolean raiSEOnDataBinding)
at System.Web.UI.Control.DataBind()
at System.Web.UI.Control.DataBindChildren()
at System.Web.UI.Control.DataBind(Boolean raiSEOnDataBinding)
at System.Web.UI.Control.DataBind()
at System.Web.UI.Control.DataBindChildren()
at System.Web.UI.Control.DataBind(Boolean raiSEOnDataBinding)
at System.Web.UI.WebControls.DetailsView.CreateChildControls(IEnumerable
dataSource,Boolean dataBinding)
at System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable
data)
at System.Web.UI.WebControls.DetailsView.PerformDataBinding(IEnumerable
data)
at System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable
data)
at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments
arguments,DataSourceViewSelectCallback callback)
at System.Web.UI.WebControls.DataBoundControl.PerformSelect()
at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
at System.Web.UI.WebControls.DetailsView.DataBind()
at storeUpdate.GvStoresSelect_SelectedIndexChanged(Object sender,EventArgs e) in line 233
at System.EventHandler.Invoke(Object sender,EventArgs e)
at System.Web.UI.WebControls.GridView.OnSelectedIndexChanged(EventArgs e)
at System.Web.UI.WebControls.GridView.HandleSelect(Int32 rowIndex)
at System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e,Boolean causesValidation,String validationGroup)
at System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source,EventArgs e)
at System.Web.UI.Control.RaiseBubbleEvent(Object source,EventArgs args)
at System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source,
EventArgs e)
at System.Web.UI.Control.RaiseBubbleEvent(Object source,EventArgs args)
at System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e)
at System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String
eventArgument)
at System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl,String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint)
InnerException:

解决方法

来自<%#Bind(“Name”)%>的值传递给SelectedValue属性,与其集合中的项不匹配.最可能的原因:

> DropDownList没有项目,因为评估发生在列表绑定之前>列表已绑定但缺少此特定值>返回的值可以为null

原文链接:https://www.f2er.com/aspnet/251565.html

猜你在找的asp.Net相关文章