您好我的GridView有问题。我有一个方法,我需要2个datakeynames,然后另一个方法,我需要一个datakey名称。我不知道该怎么处理?谁能告诉我该怎么办?我将在下面发布我的GridView代码。如果需要任何其他代码,请告诉我。感谢。
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="ObjectDataSource1" DataKeyNames="intExaminerID,sintDOLDistrictOfficeID" OnRowCommand="GridView1_RowCommand">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="txtID" Visible="false" runat="server" Text='<%# Bind("intExaminerID") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="txtDOID" Visible="false" runat="server" Text='<%# Bind("sintDOLDistrictOfficeID") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="First Name">
<ItemTemplate>
<asp:TextBox ID="txtFName" Visible='<%# IsInEditMode %>' runat="server" Text='<%# Bind("vcharFirstName") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Last Name">
<ItemTemplate>
<asp:TextBox ID="txtLName" Visible='<%# IsInEditMode %>' runat="server" Text='<%# Bind("vcharLastName") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Email">
<ItemTemplate>
<asp:TextBox ID="txtEmail" Visible='<%# IsInEditMode %>' runat="server" Text='<%# Bind("vcharEmailAddress") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Extension">
<ItemTemplate>
<asp:TextBox ID="txtPhone" Visible='<%# IsInEditMode %>' runat="server" Text='<%# Bind("vcharPhoneExtension") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="SSN Block">
<ItemTemplate>
<asp:TextBox ID="txtSSNStart" Visible='<%# IsInEditMode %>' runat="server" Text='<%# Bind("vcharSSNBlockStart") %>' Width="5em"></asp:TextBox>
<asp:TextBox ID="txtSSNEnd" Visible='<%# IsInEditMode %>' runat="server" Text='<%# Bind("vcharSSNBlockEnd") %>' Width="5em"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Action(s)">
<ItemTemplate>
<asp:Button ID="btnUpdate" runat="server" Text="Update" CommandName="Update" CommandArgument='<%# Container.DataItemIndex %>'
/>
<%--<asp:Button ID="btnUpdate" runat="server" Text="Update" OnClick="UpdateRow" />--%>
<asp:Button ID="btnDelete" runat="server" Text="Delete" CommandName="Delete" CommandArgument='<%# Container.DataItemIndex %>'
/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
答案 0 :(得分:0)
关于你想要使用密钥的方法可能有点不清楚但是你可以使用他们的名字来获取DataKeys:
//rowindex is the index of the row you want to get the keys for
string intExaminerID= GridView1.DataKeys[rowindex].Values["intExaminerID"].ToString();
string sintDOLDistrictOfficeID= GridView1.DataKeys[rowindex].Values["sintDOLDistrictOfficeID"].ToString();