我得到了这样的datagridview:
<asp:GridView ID="gvData" runat="server" AllowPaging="True" AutoGenerateColumns="False"
CellPadding="4" DataKeyNames="InquiryId" Font-Size="11px" ForeColor="Black" PageSize="20"
Width="100%" Style="text-align: center" CssClass="zebra" AlternatingRowStyle-CssClass="even">
<AlternatingRowStyle CssClass="even" />
<Columns>
<asp:TemplateField>
<ItemStyle HorizontalAlign="Center" Width="100px" />
<FooterStyle HorizontalAlign="Left" />
<ItemTemplate>
<asp:ImageButton ID="imgbtn" ImageUrl="~/Edit.jpg" runat="server" Width="25" Height="25" onclick="imgbtn_Click" />
</ItemTemplate>
<EditItemTemplate>
</EditItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="No Account">
<ItemStyle HorizontalAlign="Center" Width="100px" />
<FooterStyle HorizontalAlign="Left" />
<ItemTemplate>
<asp:Label ID="lblNoaccount0" runat="server" Text='<%# Bind("InquiryAccount") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
</EditItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Language">
<ItemStyle HorizontalAlign="center" Width="50px" />
<FooterStyle HorizontalAlign="Left" />
<ItemTemplate>
<asp:Label ID="lblSlotTime" runat="server" Text='<%# Bind("InquiryLang") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Amount">
<ItemStyle HorizontalAlign="Center" Width="20px" />
<FooterStyle HorizontalAlign="Left" />
<ItemTemplate>
<asp:Label ID="lblInquiryAmount" runat="server" Text='<%# Bind("InquiryAmount") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Response">
<ItemStyle HorizontalAlign="Center" Width="70px" />
<FooterStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:Label ID="lblResponse" runat="server" Text='<%# Bind("InquiryResponse") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
我想通过单击图像按钮来获取行值,这是代码:
Protected Sub imgbtn_Click(ByVal sender As Object, ByVal e As ImageClickEventArgs)
Dim btndetails As ImageButton = TryCast(sender, ImageButton)
Dim gvrow As GridViewRow = DirectCast(btndetails.NamingContainer, GridViewRow)
lblID.Text = gvData.DataKeys(gvrow.RowIndex).Value.ToString()
lblusername.Text = gvrow.Cells(1).Text
txtfname.Text = gvrow.Cells(2).Text
txtlname.Text = gvrow.Cells(3).Text
txtCity.Text = gvrow.Cells(4).Text
txtDesg.Text = gvrow.Cells(5).Text
Me.pnlGrid_ModalPopupExtender.Show()
End Sub
但是当我调试它时,我只得到gvData.DataKeys(gvrow.RowIndex).Value.ToString()
值,其他值只是给我空字符串。我的代码有什么问题??