从查询字符串id中选择并显示Gridview行 [英] Select and Show Gridview row from query string id

查看:70
本文介绍了从查询字符串id中选择并显示Gridview行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站第1页上的应用程序有一个gridview。我已经在第1页配置了gridview,这样当你点击一行时,它会用一个查询字符串将你重定向到第2页。



Gridview selectedindexchanged事件

  Dim  rowIndex 作为  Integer  = pastduegrid.SelectedIndex 
Dim strValue As 字符串 = pastduegrid.DataKeys(rowIndex).Value.ToString()

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



所以字符串是http://mysite.com/page2.aspx?id=1335



现在我在第2页上有另一个带有gridview的应用程序,带有分页功能。如何在gridview 2上选择并设置包含字符串id 1335的行?即使它位于gridview 2的第10页?



任何帮助都将不胜感激。

解决方案

您可以使用一些自定义逻辑找到显示该记录的gridview的页码。



这样的事情。基于该网格的总页数,每页上的记录数,列表中该项的索引。



因此,一旦您确定了页码,请将其设置为作为该索引的当前页面,然后设置焦点。



希望这有助于推导逻辑。



谢谢,

Lijo


这是我最终在我的网站第2页的网格2上做的事情,在Lijo的帮助下建议找到页面索引该行已打开。



 受保护  Sub  GridView2_DataBound( ByVal  sender  As  对象 ByVal  e  As  EventArgs)句柄 GridView2.DataBound 

如果会话( GetDatString IsNot Nothing 然后
Dim con As SqlConnection
Dim cmd As SqlCommand
con.ConnectionString = SqlDataSource1.ConnectionString
con.Open()
cmd.Connection = con
Dim i As 整数 = 0
Dim gridPage 作为 整数 = 1
cmd.Comm andText = SELECT * FROM PROProspects ORDER BY PROOrgName ASC
Dim lrd As SqlDataReader = cmd.ExecuteReader
while lrd .Read
i + = 1
如果 i = 32 然后
gridPage + = 1
i = 1
结束 如果
如果 lrd( PROID)=会话( GetDatString然后
退出
结束 如果
结束 while
GridView2.PageIndex = gridPage - 1
For 每个作为 GridViewRow GridView2.Rows
如果 GridView2.DataKeys(row.RowIndex).Value = Session( GetDatString然后
GridView2.SelectedIndex = row.RowIndex
结束 如果
Next
SqlDataSource2.DataBind()
FormView1.ChangeMode(FormViewMode。 ReadOnly
FormView1.DataBind()
结束 如果


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

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.

解决方案

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


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.

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


这篇关于从查询字符串id中选择并显示Gridview行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆