文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>GridView控件使用技巧——用DataKeyNames来保存绑定的datatable更多的字段值

GridView控件使用技巧——用DataKeyNames来保存绑定的datatable更多的字段值

时间:2010-09-10  来源:linzheng

1 GridView控件代码          

                             <asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False"
                                BorderWidth="1px" CellPadding="1" ForeColor="#333333" OnRowDataBound="GridView1_RowDataBound"
                                Width="100%" DataKeyNames="FNO,FID,FDetail" meta:resourcekey="GridView1Resource1">
                                <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                                <EditRowStyle BackColor="#2461BF" />
                                <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                                <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                                <AlternatingRowStyle BackColor="White" />
                                <HeaderStyle CssClass="tabletitle" />
                                <Columns>
                                    <asp:BoundField DataField="Fclass" HeaderText="班级" ReadOnly="True" meta:resourcekey="BoundFieldResource1">
                                        <ItemStyle HorizontalAlign="Left" Width="200px" />
                                    </asp:BoundField>
                                    <asp:BoundField DataField="FName" HeaderText="名字" ReadOnly="True" meta:resourcekey="BoundFieldResource2">
                                        <ItemStyle HorizontalAlign="Left" />
                                    </asp:BoundField>
                                    <asp:BoundField DataField="FDetail" HeaderText="操作" ReadOnly="True" meta:resourcekey="BoundFieldResource3">
                                        <ItemStyle HorizontalAlign="Left" Width="150px" />
                                    </asp:BoundField>
                                    <asp:TemplateField meta:resourcekey="TemplateFieldResource1">
                                        <HeaderTemplate>
                                            <asp:Label ID="lbAuthorize" runat="server" Text="选择" meta:resourcekey="Resource1"></asp:Label>
                                            <asp:CheckBox ID="chkSelectAll" runat="server" onclick="selectAll(this)"  />
                                        </HeaderTemplate>
                                        <ItemTemplate>
                                            <asp:CheckBox ID="chkSelect" runat="server" Text=" " />
                                        </ItemTemplate>
                                        <ItemStyle Width="120px" />
                                        <HeaderStyle Width="120px" />
                                    </asp:TemplateField>
                                </Columns>
                                <RowStyle HorizontalAlign="Left" />
                            </asp:GridView>

 

2DataKeyNames使用

调用DataKeyNames="FNO,FID,FDetail"   字段的值如下

GridView1.DataKeys[row.RowIndex].Values[0]

GridView1.DataKeys[row.RowIndex].Values[1]

GridView1.DataKeys[row.RowIndex].Values[2]

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载