访问多个gridkeys时,“没有类型整数的默认成员”错误

时间:2016-07-22 18:01:48

标签: asp.net vb.net gridview

我有一个带有2个数据键的gridview。 Gridview的定义如下:

<asp:GridView ID="grid1"    runat="server"  AutoGenerateColumns="False" DataKeyNames="ID1, ID2" >
<Columns>
<asp:BoundField HeaderText="" DataField="ID1" Visible="false"> </asp:BoundField>    
<asp:BoundField HeaderText="" DataField="ID2" Visible="false"> </asp:BoundField>                     
<asp:BoundField HeaderText="Full Name" DataField="fullname" ItemStyle-Width="200px">
<HeaderStyle Width="350px" /> </asp:BoundField>
<asp:ButtonField ButtonType="button" ControlStyle-CssClass="btn" ControlStyle-Width="30px" CommandName="Select" 
 HeaderText="" Text="+" ItemStyle-Width="30px" />
</Columns>

然后在VB代码后面我有一个sub来处理gridview命令:

Protected Sub grid1_RowCommand(ByVal sender As Object,ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles grid1.RowCommand
    Dim currentCommand As String = e.CommandName
    If currentCommand = "Select" Then
        Dim currentRowIndex As Integer = Int32.Parse(e.CommandArgument.ToString())
        Dim id1 As Integer = grid1.DataKeys(currentRowIndex).Value("ID1")
        Dim id2 As Integer = grid1.DataKeys(currentRowIndex).Value("ID2")
        '***call another sub with these IDs***
    End If
End Sub

当我尝试运行它时,我得到一个“找不到类型整数的默认成员”错误,代码在Dim id1 ....行处断开。

我也尝试将多个数据密钥称为(0)和(1),但是会遇到同样的问题。

我错过了一些非常明显的东西吗?

1 个答案:

答案 0 :(得分:1)

小学生错误! 应该是......

/index

即。值 s 而不是值!