<asp:GridView ID="PageGrid" runat="server" AutoGenerateColumns="False" CssClass="dgv"Width="100%" DataKeyNames="Id" OnRowDataBound="PageGrid_RowDataBound"> <Columns> <asp:TemplateField> <ItemTemplate> <asp:CheckBox ID="chkitem" runat="server" /> </ItemTemplate>
<HeaderStyle Width="30px" /> </asp:TemplateField> <asp:TemplateField> <ItemTemplate> <asp:Label ID="lblRowNumber" runat="server" Text='<%# Container.DataItemIndex + 1 %>'></asp:Label> <asp:HiddenField ID="hfReimId" runat="server"></asp:HiddenField> </ItemTemplate> <HeaderStyle Width="30px" /> </asp:TemplateField> <asp:TemplateField HeaderText="填写时间">
<ItemTemplate> <asp:TextBox ID="txtFillDate" CssClass="easyui-datebox" runat="server" Width="120px" Text='<%# Eval("FillDate") %>'></asp:TextBox> </ItemTemplate>
<HeaderStyle Width="80px" />
</asp:TemplateField> </Columns> </asp:GridView>
从
DataKeyNames="Id"
这句话可以看出,上面的主键是Id
关于主键,建议看下这篇文章:http://www.cnblogs.com/LifeKingcn/archive/2012/08/21/2649380.html
DataKeyNames表示主键的列名,可以通过GridViewEntity.DataKeys[RowIndex]["ColumsName"]来获取它的值