Link to home
Start Free TrialLog in
Avatar of Wildone63
Wildone63

asked on

Gridview Selected Index Changed

I have an aspx page that has a gridview and a form view.

When the page loads the gridview is filled with data.

When a user selects a row in the grid view i want the form view to be updated to that record.

Here is what I am trying

In the GridView1_SelectedIndexChanged... But it does not work... Any Ideas?

Thanks

    Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
        MsgBox("It was selected")
        FormView1.DataBind()

    End Sub
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

How do you select the row? Do you have a Select column?
Avatar of Wildone63
Wildone63

ASKER

Yes there is a select row column
Then the selectedindexchanged event should fire. Have you put a breakpoint on it to see if it is?
Yes, and it is firing

so I have this The msgbox tells me the event fired, then I am doing the formview1.databind, but the formview does not update to the selected record.


    Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
        MsgBox("It was selected")
        FormView1.DataBind()

    End Sub
How does formview know what record to show?
Well I am not sure, I was assuming because both the formview and the dataview are using the same sql data source
I got it.

    Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
        Dim RowIndex As Integer = Convert.ToInt16(e.CommandArgument.ToString)

        Dim gv As GridView = CType(sender, GridView)
        Dim PgIndex As Integer = gv.PageIndex

        Dim PgSize As Integer = gv.PageSize
        FormView1.PageIndex = RowIndex + (PgIndex * PgSize)

        FormView1.DataBind()

    End Sub
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

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