继续自IDbObject 无法绑定Gridview

Dec 18, 2009 at 5:40 PM

因为是重构一个单机的软件,,所以,,最好是使用原来的数据库,下面实体类是因CodeGen生成的

public class STU_Main : IDbObject  {
 [DbKey(IsDbGenerate = false)]
 public long STU_ID;
 [AllowNull] [Length(50)] public string StuName;
 public short? Class_ID;
 [AllowNull] [Length(50)] public string GroupNo;
 [AllowNull] [Length(50)] public string GroupName;
 [AllowNull] [Length(10)] public string Sex;
 public DateTime? Birthday;
 public short? Nation_ID;
 [AllowNull] [Length(50)] public string StuNo;
 [AllowNull] [Length(100)] public string Address;
 public short? STU_Year;
 public short? TotalNum;
 [AllowNull] [Length(10)] public string TotalText;
 [AllowNull] [Length(10)] public string TotalCode;
 public DateTime? CreateDate;
 [AllowNull] [Length(10)] public string AreaCode;
    }

<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
        AllowSorting="True" AutoGenerateColumns="False"
        >
        <Columns>
                       <asp:BoundField DataField="StuName" HeaderText="StuName"
                SortExpression="StuName" />
            <asp:BoundField DataField="Class_ID" HeaderText="Class_ID"
                SortExpression="Class_ID" />
            <asp:BoundField DataField="GroupNo" HeaderText="GroupNo"
                SortExpression="GroupNo" />
            <asp:BoundField DataField="GroupName" HeaderText="GroupName"
                SortExpression="GroupName" />
            <asp:BoundField DataField="Sex" HeaderText="Sex" SortExpression="Sex" />
            <asp:BoundField DataField="Birthday" HeaderText="Birthday"
                SortExpression="Birthday" />
            <asp:BoundField DataField="Nation_ID" HeaderText="Nation_ID"
                SortExpression="Nation_ID" />
            <asp:BoundField DataField="StuNo" HeaderText="StuNo" SortExpression="StuNo" />
            <asp:BoundField DataField="Address" HeaderText="Address"
                SortExpression="Address" />
            <asp:BoundField DataField="STU_Year" HeaderText="STU_Year"
                SortExpression="STU_Year" />
            <asp:BoundField DataField="TotalNum" HeaderText="TotalNum"
                SortExpression="TotalNum" />
            <asp:BoundField DataField="TotalText" HeaderText="TotalText"
                SortExpression="TotalText" />
            <asp:BoundField DataField="TotalCode" HeaderText="TotalCode"
                SortExpression="TotalCode" />
            <asp:BoundField DataField="CreateDate" HeaderText="CreateDate"
                SortExpression="CreateDate" />
            <asp:BoundField DataField="AreaCode" HeaderText="AreaCode"
                SortExpression="AreaCode" />
        </Columns>
    </asp:GridView>

List<STU_Main> list = DbEntry.Context.From<STU_Main>().Where(null).Select();
            this.GridView1.DataSource = list;
            this.GridView1.DataBind();

在选定的数据源上未找到名为“StuName”的字段或属性。

说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.Web.HttpException: 在选定的数据源上未找到名为“StuName”的字段或属性。

源错误:

行 33:             List<STU_Main> list = DbEntry.Context.From<STU_Main>().Where(null).Select();
行 34:             this.GridView1.DataSource = list;
行 35:             this.GridView1.DataBind();
行 36: 
行 37:             //StringBuilder sb = new StringBuilder();


源文件: d:\SchoolWeb\Tiyu\TiyuWebsite\Tiyu\Student.aspx.cs    行: 35

 

 

 

 

Coordinator
Dec 19, 2009 at 1:37 AM

GridView 无法直接绑定字段,有两种方法解决:

  • 使用模板列
  • 把字段改成属性