将 aTemplateField
与HyperLink
内部控件一起使用,然后在RowDataBound
代码隐藏中的事件中使用,只需将NavigateUrl
属性设置为值,如下所示:
标记:
<asp:GridView id="GridView1" runat="server"
OnRowDataBound="GridView1_RowDataBound">
<Columns>
...Other columns here...
<asp:TemplateField>
<ItemTempalte>
<asp:HyperLink id="HyperLink1" runat="server" Text="Details" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
代码隐藏:
protected void GridView1_RowDataBound(Object sender, GridViewRowEventArgs e)
{
// Only interact with the data rows, ignore header and footer rows
if(e.Row.RowType == DataControlRowType.DataRow)
{
// Find the hyperlink control by ID
var theHyperLink = e.Row.FindControl("HyperLink1") as HyperLink;
// Verify we found the hyperlink before we try to use it
if(theHyperLink != null)
{
// Set the NavigateUrl value here
theHyperLink.NavigateUrl = String.Format("DetailedPage.aspx?OrderNo={0}&filename='{1}'", theOrderNumber.ToString(), theFileName);
}
}
}
注意:theOrderNumber
和theFileName
将是从数据库加载页面时确定的值,例如。