首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何让grdview列超链接到其他页面?

问如何让grdview列超链接到其他页面?
EN

Stack Overflow用户
提问于 2016-12-05 09:48:21
回答 1查看 107关注 0票数 1

我有来自sql的数据源的网格视图。目前,其中一个栏目,它是总保证人,所有的数据都链接到相同的页面。但我想让标题“Total column”超链接或可点击到其他页面,而不是Total Guarantor列中的数据。

下面是我使用的代码:

代码语言:javascript
复制
           <asp:HyperLinkField DataTextField="Total Guarantor" DataNavigateUrlFields="Total Guarantor"  DataNavigateUrlFormatString="guarantoedetails.aspx?custno={0}" Text="Total Guarantor" HeaderText="Total Guarantor" />

​

EN

回答 1

Stack Overflow用户

发布于 2016-12-05 16:42:06

为此,您可以使用OnRowCreated事件。

代码语言:javascript
复制
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
    //check if the row is the header row
    if (e.Row.RowType == DataControlRowType.Header)
    {
        //the header cell number where to put the link
        int cellNumber = 1;

        //cast the cell in the header
        TableCell headerCell = e.Row.Cells[cellNumber];

        //create a hyperlink
        HyperLink link = new HyperLink();
        link.Text = "myLink";
        link.NavigateUrl = "/otherPage.aspx";

        //remove existing controls from the cell
        headerCell.Controls.Clear();

        //add the hyperlink to the cell
        headerCell.Controls.Add(link);
    }
}

VB

代码语言:javascript
复制
Protected Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
    'check if the row is the header row
    If (e.Row.RowType = DataControlRowType.Header) Then
        'the header cell number where to put the link
        Dim cellNumber As Integer = 1

        'cast the cell in the header
        Dim headerCell As TableCell = e.Row.Cells(cellNumber)

        'create a hyperlink
        Dim link As HyperLink = New HyperLink
        link.Text = "myLink"
        link.NavigateUrl = "/otherPage.aspx"

        'remove existing controls from the cell
        headerCell.Controls.Clear

        'add the hyperlink to the cell
        headerCell.Controls.Add(link)
    End If        
End Sub
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40965969

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档