可以使用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 Sub
那麼你正在嘗試是,當你點擊總計列,那麼它應該重定向到與細節另一個頁面來獲得相關的行數據。是嗎? –
不,現在,Total列中的數據正被超鏈接/重定向到其他頁面(就像代碼一樣)。而不是數據,我想要總列(標題)超鏈接到其他頁面。 – mir
標題可以作爲HyperLink。但是,這樣做的意義何在,您希望如何重定向到其他頁面? –