Click here to Skip to main content
15,889,200 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a gridview on an application on page 1 of my website. I have configured the gridview on page 1 so that when you click on a row it redirects you to page 2 with a query string.

Gridview selectedindexchanged event
VB
Dim rowIndex As Integer = pastduegrid.SelectedIndex
        Dim strValue As String = pastduegrid.DataKeys(rowIndex).Value.ToString()

        Response.Redirect("http://mysite.com/page2.aspx?id=" + "" + strValue)

so the string would be http://mysite.com/page2.aspx?id=1335

Now I have another application with a gridview on page 2 with paging. How would I select and set in focus the row containing the string id of 1335 on gridview 2? even if it is on page 10 of gridview 2?

Any help would be appreciated.
Posted
Comments
ZurdoDev 10-Sep-13 15:53pm    
I think you'll find it much easier to filter your second grid rather than try to go to a certain page.
Lijo Rajan 10-Sep-13 16:25pm    
Is it ok if you display that record(matching that string id) in the first page of that gridview 2?
PTG.Jake 10-Sep-13 16:29pm    
Lijo Rajan: It would be ok if that was the only record selected and showing at all in gridview 2.

you can find out the page number of the gridview where that record is displayed by using some custom logic.

Some thing like this. Based on the total pages of that grid,number of records on each page,index of that item in the list.

So once u identified the page number, set that as the current page of that index and then set the focus.

Hope this helps to derive the logic.

Thanks,
Lijo
 
Share this answer
 
Here's what I ended up doing on grid 2 that is on page 2 of my site with the help from Lijo suggesting finding the page index the row is on.

VB
Protected Sub GridView2_DataBound(ByVal sender As Object, ByVal e As EventArgs) Handles GridView2.DataBound

        If Session("GetDatString") IsNot Nothing Then
            Dim con As New SqlConnection
            Dim cmd As New SqlCommand
            con.ConnectionString = SqlDataSource1.ConnectionString
            con.Open()
            cmd.Connection = con
            Dim i As Integer = 0
            Dim gridPage As Integer = 1
            cmd.CommandText = "SELECT * FROM PROProspects ORDER BY PROOrgName ASC"
            Dim lrd As SqlDataReader = cmd.ExecuteReader
            While lrd.Read
                i += 1
                If i = 32 Then
                    gridPage += 1
                    i = 1
                End If
                If lrd("PROID") = Session("GetDatString") Then
                    Exit While
                End If
            End While
            GridView2.PageIndex = gridPage - 1
            For Each row As GridViewRow In GridView2.Rows
                If GridView2.DataKeys(row.RowIndex).Value = Session("GetDatString") Then
                    GridView2.SelectedIndex = row.RowIndex
                End If
            Next
            SqlDataSource2.DataBind()
            FormView1.ChangeMode(FormViewMode.ReadOnly)
            FormView1.DataBind()
        End If
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900