我的代码是(Asp.Net,C#)
int index = Convert.ToInt16(e.CommandArgument);
string str = GridView2.DataKeys[index].Value.ToString();
Session["studyuid2"] = str;
第二行向我抛出错误索引超出范围。必须是非负数且小于集合的大小。参数名称:索引
我的gridview是
<asp:GridView ID="GridView2" runat="server" AllowPaging="True" Height="100px"
RowStyle-Height="25px" HeaderStyle-Height="30px" FooterStyle-Height="30px"
CellPadding=5 CellSpacing=5
AutoGenerateColumns="False"
DataSourceID="SqlDataSource1" EnableModelValidation="True"
Width="100%"
DataKeyNames="StudyUID"
onrowcommand="GridView2_RowCommand"
AllowSorting="True">
<RowStyle Height="25px"></RowStyle>
<Columns>
-------------------------------------------
</Columns>
<FooterStyle Height="30px"></FooterStyle>
<HeaderStyle Height="30px"></HeaderStyle>
</asp:GridView>