我有来自sql的数据源的网格视图。目前,其中一个栏目,它是总保证人,所有的数据都链接到相同的页面。但我想让标题“Total column”超链接或可点击到其他页面,而不是Total Guarantor列中的数据。
下面是我使用的代码:
<asp:HyperLinkField DataTextField="Total Guarantor" DataNavigateUrlFields="Total Guarantor" DataNavigateUrlFormatString="guarantoedetails.aspx?custno={0}" Text="Total Guarantor" HeaderText="Total Guarantor" />
发布于 2016-12-05 16:42:06
为此,您可以使用OnRowCreated事件。
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
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 Subhttps://stackoverflow.com/questions/40965969
复制相似问题