为什么当我尝试使用会话状态设置我的GridView排序时,突然间我的GridView不再有DataKeys?我所做的只是将下面的代码放入我的Page_Init中;GridView丢失DataKeys
Dim SortDirection As String = Session("SortDir")
Dim sortExpression As String = Session("SortExp")
If Not SortDirection Is Nothing AndAlso Not sortExpression Is Nothing Then
If (SortDirection = "asc") Then
GridView1.Sort(sortExpression, WebControls.SortDirection.Ascending)
Else
GridView1.Sort(sortExpression, WebControls.SortDirection.Descending)
End If
End If
但如果我评论了这一点比我的其他方法不碰撞出更多的为我的GridView现在有它的DataKeys。为什么是这样?
UPDATE
这是停止工作时,上面的代码是在适当位置中的特定行。
Dim UserID = GridView1.DataKeys(e.RowIndex).Value.ToString
根据调试器GridView1有列但它的DataKeys计数是0.我收到的错误是;
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
什么是你的错误,当你其他的方法崩溃?你正在执行哪些操作会导致错误? – jadarnel27 2012-08-13 15:10:45
@ jadarnel27请参阅更新。 – windowskm 2012-08-13 15:18:20
感谢您添加额外信息! – jadarnel27 2012-08-13 15:22:20