【问题标题】:Pass values from QueryString parameter in GridView hyperlink从 GridView 超链接中的 QueryString 参数传递值
【发布时间】:2010-01-14 20:11:34
【问题描述】:

我正在使用 GridViewHyperLink 列,我想要执行以下操作:

<asp:HyperLinkField DataNavigateUrlFields="DID"  
DataNavigateUrlFormatString="~/student/group/document/Body.aspx?DID={0}&GN={QueryString("GN")}" HeaderText="View Document" Text="view" />

如何从QueryString 参数中检索GN 的值并将其添加到HyperLink 列?

【问题讨论】:

    标签: asp.net gridview query-string


    【解决方案1】:

    在标记中执行此操作对您有多重要?我相当确定您不能在标记中使用DataNavigateUrlFieldsDataNavigateUrlFormatString 执行此操作,但您可以在 RowDataBound 事件的代码中执行此操作:

    Private Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
    
        Dim link As HyperLink
        Dim row As DataRow
    
        If e.Row.RowType = DataControlRowType.DataRow Then
            'Get the row we are binding to
            row = CType(e.Row.DataItem, DataRowView).Row
    
            'Find the hyperlink control we want to set the link for
            link = CType(e.Row.Controls(1).Controls(0), HyperLink)
    
            'Check if the querystring we want to include is missing or empty
            If Request.QueryString("GN") Is Nothing Or Request.QueryString("GN") Is String.Empty Then
                'If there is no querystring then we can only bind to the DID
                link.NavigateUrl = "~/student/group/document/Body.aspx?DID=" & row.Item("DID").ToString
    
            Else
                'The querystring element is present so include it in the link
                link.NavigateUrl = "~/student/group/document/Body.aspx?DID=" & row.Item("DID").ToString & "&GN=" & Request.QueryString("GN").ToString
    
            End If
    
        End If
    
    End Sub
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-02-17
      • 2017-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-29
      相关资源
      最近更新 更多