Link to home
Start Free TrialLog in
Avatar of vzorn
vzornFlag for United States of America

asked on

Add handler to embedded gridview

I have embedded a gridview into another gridview.  It works great except I want the user to be able to "select" a record in the child gridview and I can then display a details view.  I am not sure how to get the "selectedindexchanged"  onto the child gridview.  Here is my code where I bind the child gridview.  

Private Sub gvCounts_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvCounts.RowDataBound

If e.Row.RowType = DataControlRowType.DataRow Then
            Dim iKey As Integer
            iKey = gvCounts.DataKeys(e.Row.RowIndex).Value

            Dim mtg As ConnectionStringSettings
            mtg = ConfigurationManager.ConnectionStrings("MtgFraud")
            Dim connection As SqlConnection
            connection = New SqlConnection()
            connection.ConnectionString = mtg.ConnectionString

            Dim cmd2 As New SqlCommand()
            cmd2 = connection.CreateCommand()
            cmd2.CommandType = CommandType.Text
            Dim s2 As String

            s2 = "Select * from viewDefendantCountDisplay where LinkCaseCountsID = " & iKey

            cmd2.CommandText = s2
            Dim dr2 As SqlDataReader = cmd2.ExecuteReader()
            Dim gvCountsDefendantsChild As GridView
            'DataGrid dgChildren = (DataGrid)e.Item.FindControl("dgChildren");
            gvCountsDefendantsChild = e.Row.FindControl("gvCountsDefendantsChild")
            gvCountsDefendantsChild.DataSource = dr2

            AddHandler gvCountsDefendantsChild.SelectedIndexChanged, AddressOf gvCountsDefendantsChild_SelectedIndexChanged

        End If
End Sub
Sub gvCountsDefendantsChild_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)

        ' Get the currently selected row using the SelectedRow property.

        Dim AuthorsGridView As GridView = CType(sender, GridView)
        Dim row As GridViewRow = AuthorsGridView.SelectedRow

    End Sub
** the AddHandler does not seem to do anything.

Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vzorn


Now why didn't I think of that?  
Thanks a bunch, it works great!!