C#-DropDownList导致错误:对象引用未设置为对象的实例
作者:互联网
我不断收到此错误,不知道为什么.我搜索并扫描了asp.net网站两天了,因此我需要一些帮助.错误是:
Object reference not set to an instance of an object
这是我的代码:
DropDownList DropDownList1 =(DropDownList)ListView1.InsertItem.FindControl("DropDownList1");
string highToLow = DropDownList1.SelectedValue;
string lowToHigh = DropDownList1.SelectedValue;
if (highToLow == "1")
{
var exmapleFilter = from users in testEntities.users
orderby users.id descending
select users;
ListView1.DataBind();
}
我将下拉列表的值设置为1(高)和2(低),更改了选定的索引后,我想运行ADO.net实体框架代码以返回排序的数据列表.
我目前正在使用linq数据源和列表视图来显示数据库中的内容.
谢谢.
编辑:
这是堆栈跟踪
System.NullReferenceException was unhandled by user code
Message=Object reference not set to an instance of an object.
Source=App_Web_s0ked5y3
StackTrace:
at Default.DropDownList1_SelectedIndexChanged(Object sender, EventArgs e)
in Default:line 120
at System.Web.UI.WebControls.ListControl.OnSelectedIndexChanged(EventArgs e)
at System.Web.UI.WebControls.DropDownList.RaisePostDataChangedEvent()
at System.Web.UI.WebControls.DropDownList.System.Web.UI.IPostBackDataHandler.
RaisePostDataChangedEvent()
at System.Web.UI.Page.RaiseChangedEvents()
at System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException:
解决方法:
检查您是否在列表视图中
<InsertItemTemplate>
....
<asp:DropDownList ID="DropDownList1" runat="server" />
....
与…关联
ListView1.InsertItem.FindControl("DropDownList1");
标签:visual-studio-2010,drop-down-menu,asp-net,c,entity-framework 来源: https://codeday.me/bug/20191201/2078291.html