【问题标题】:DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'o_id'DataBinding:“System.Data.DataRowView”不包含名为“o_id”的属性
【发布时间】:2016-03-28 08:59:33
【问题描述】:
when I am trying to bind data to GridView in asp.net it shows the error     "DataBinding: 'System.Data.DataRowView' does not contain a property with the   name 'o_id'..". can anyone one please help me. 

this is my database table fields: 
         o_id int primary key identity(1,1),
         o_date nvarchar(20) ,
         o_time nvarchar(20),

        name_project nvarchar(60),

.aspx 页面

  <asp:GridView ID="GvProj" runat="server"  AllowPaging="True"   CssClass="AllGrid" 
        PagerStyle-CssClass="pgrAll"  DataKeyNames="o_id">
        <PagerStyle CssClass="pgrAll"></PagerStyle>
      <RowStyle BackColor="#ffffff" ForeColor="#000000"    />
     <HeaderStyle BackColor="#4a70d0" ForeColor="#ffffff"  />
     <AlternatingRowStyle BackColor="#c0c0c0"   ForeColor="#000000"FontSize="14px" />
    </asp:GridView>

.cs 文件

cmd.CommandText = "从 OrderManagement 中选择 o_id 作为 ID,o_date 作为 DATE,name_project 作为 NAME";

                int count = cmd.ExecuteNonQuery();
                DataTable dt = new DataTable();



                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(dt);
                GvProj.DataSource = dt;
                GvProj.DataBind();
                GvProj.Visible = true;
                GvInvidual.Visible = false;

【问题讨论】:

  • 你在哪里将你的 db 列绑定到 gridview?
  • 我只想从名为“OrderManagement”的表中选择数据库数据,并希望在名为“GvProj”的网格视图中显示。
  • 但是当我在 gridview 属性中提供 DatakeyName 时,它​​不起作用。否则它会工作
  • 为此您需要将这些 DB 行绑定到 aspx gridview 标记
  • 尝试在 datakeynames 中提供 ID

标签: asp.net gridview


【解决方案1】:

您的 o_ID 数据库名称是 ID 因为您没有检索相同的名称并尝试使用别名名称更改该列。所以尝试像这样改变:

DataKeyNames="ID"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多