我不断收到此错误,不知道为什么。我用谷歌搜索并扫描了 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: