0

嗨,我已经在 GridView 上编写了这个扩展方法。更改所选索引后,我希望触发 SelectedIndexChanged 事件。但是,这并没有发生。有什么特别的原因吗?我怎样才能解决这个问题?

<Extension()>
       Public Sub SelectRowByCallId(ByVal gridviewObj As GridView, ByVal callId As String)
        Dim selectedIndex As Int32 = 0
        Dim pageIndex As Int32 = 0
        Dim gridViewPages As Int32 = gridviewObj.PageCount

        For index = 0 To gridViewPages
            gridviewObj.PageIndex = index
            gridviewObj.DataBind()

            For i = 0 To gridviewObj.DataKeys.Count - 1
                If (Convert.ToString(gridviewObj.DataKeys(i).Value) = callId) Then
                    selectedIndex = i
                    pageIndex = index
                    Exit For
                End If

            Next i

        Next index

        gridviewObj.PageIndex = pageIndex
        gridviewObj.SelectedIndex = selectedIndex
        gridviewObj.DataBind()


    End Sub
4

2 回答 2

0

如果 Aristos 是对的,则将 AutoPostBack 设置为 True

于 2012-11-12T08:07:17.947 回答
0

设置SelectedIndex属性不会触发事件,但调用SelectRow方法会。

于 2012-11-12T08:12:01.037 回答