0

我在 GridView1.DataBind() 行中收到以下消息:

对象“MyApp.Page3”上的属性访问器“Title”引发了以下异常:“对象 > 引用未设置为对象的实例。”

我的代码隐藏如下所示:

<%@ Page Title="Page3" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Page3.aspx.cs" Inherits="Hedis2013WebApp.Page3" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="FeaturedContent" runat="server">
    <br />
    <asp:TextBox ID="textboxHMO" runat="server" Width="200px"></asp:TextBox>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
    <asp:GridView ID="GridView1" runat="server" 
        AutoGenerateSelectButton="true" 
        DataKeyNames="employergroup_id" 
        EmptyDataText="No Data to Show" 
        OnSelectedIndexChanged="GridView1_SelectedIndexChanged" >
    </asp:GridView>    
</asp:Content>

我的代码如下所示:

protected void LoadGridView()
{
    try
    {
        int
            employergroup_id = (int)Session["Employergroup_id"];

        var db = new pec_prod_on_epic();
        ((IObjectContextAdapter)db).ObjectContext.ContextOptions.UseCSharpNullComparisonBehavior = true; //this.Configuration.UseDatabaseNullSemantics = true;  // EF6
        ((IObjectContextAdapter)db).ObjectContext.CommandTimeout = 600;
        var qry = from p3 in db.Page3 where p3.employergroup_id == employergroup_id select p3;
        var result = qry.ToList();
        GridView1.DataSource = result;
        GridView1.DataBind();
    }
    catch (Exception ex)
    {
        Console.Write(ex.Message.ToString());
    }
}

我的母版页的相关部分如下所示:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="Hedis2013WebApp.SiteMaster" %>
<%--<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>--%>
<!DOCTYPE html>
<html lang="en">
<head runat="server">
    <meta charset="utf-8" />
    <title><%: Page.Title %> - Portal</title>

我想不出我可能会做出任何改变来实现这一点。有任何想法吗?

4

1 回答 1

0

问题出在以下代码行中:

var qry = from p3 in db.Page3 where p3.employergroup_id == employergroup_id select p3;

我认为您错误地删除了上述查询中的单词 (SELECT,DELETE OR UPDATE)。让我知道它是否解决了您的问题。

于 2013-08-20T20:49:41.117 回答