VS.net 2005 中,怎么样对GridView绑定设置主键字段啊
就像在VS.NET2003中用的GridView1.DataKey="字段名"的效果,请问怎么实现,还请路过同手,支支招!!~~...
就像在VS.NET 2003中用的 GridView1.DataKey="字段名" 的效果,请问怎么实现,还请路过同手,支支招!!~~
展开
2个回答
展开全部
2005跟2003一样的 用DataKeyNames="字段名就可以"
这是我写的一个gridview 你参考下
<asp:GridView ID="myGrid" runat="server" Width=800px Height=484px AutoGenerateColumns="False" OnRowDataBound="myGrid_RowDataBound" DataKeyNames="id" OnRowCommand="myGrid_RowCommand">
<Columns>
<asp:BoundField DataField="name" HeaderText="用户名" />
<asp:BoundField DataField="turename" HeaderText="真实姓名" />
<asp:BoundField DataField="depotname" HeaderText="单位名称" />
<asp:BoundField DataField="departmentname" HeaderText="部门名称" />
<asp:BoundField DataField="duty" HeaderText="职务" />
<asp:TemplateField HeaderText="审核状态">
<ItemTemplate>
<%#Eval("pass").ToString() == "True"?"审核":"未审核" %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="审核状态">
<ItemTemplate>
<asp:Button ID="modify" runat="server" CommandName="modify" Text="修改状态" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="删除用户">
<ItemTemplate>
<asp:Button ID="clean" runat="server" CommandName="clean" Text="删除用户" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="修改信息">
<ItemTemplate>
<asp:Button ID="update" runat="server" CommandName="update" Text="修改信息" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
这是我写的一个gridview 你参考下
<asp:GridView ID="myGrid" runat="server" Width=800px Height=484px AutoGenerateColumns="False" OnRowDataBound="myGrid_RowDataBound" DataKeyNames="id" OnRowCommand="myGrid_RowCommand">
<Columns>
<asp:BoundField DataField="name" HeaderText="用户名" />
<asp:BoundField DataField="turename" HeaderText="真实姓名" />
<asp:BoundField DataField="depotname" HeaderText="单位名称" />
<asp:BoundField DataField="departmentname" HeaderText="部门名称" />
<asp:BoundField DataField="duty" HeaderText="职务" />
<asp:TemplateField HeaderText="审核状态">
<ItemTemplate>
<%#Eval("pass").ToString() == "True"?"审核":"未审核" %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="审核状态">
<ItemTemplate>
<asp:Button ID="modify" runat="server" CommandName="modify" Text="修改状态" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="删除用户">
<ItemTemplate>
<asp:Button ID="clean" runat="server" CommandName="clean" Text="删除用户" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="修改信息">
<ItemTemplate>
<asp:Button ID="update" runat="server" CommandName="update" Text="修改信息" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询