前台代码:
<asp:GridView ID="GridView1" runat="server" OnRowDataBound="OnRow_Bound" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="标题">
<ItemTemplate>
<a href="#" class="gvlink" runat="server" id="html_a">
<asp:Label ID="Labelyjje" runat="server" Text="测试"></asp:Label></a>
</ItemTemplate>
</asp:TemplateField>
</Columns>
后台代码:
先添加引用:using System.Web.UI.HtmlControls;
//gv行处理
public void OnRow_Bound(object sender, GridViewRowEventArgs e)
{
if ((e.Row.RowType == DataControlRowType.DataRow)) //判断是否是表头
{
HtmlAnchor html_a = e.Row.FindControl("html_a") as HtmlAnchor;
html_a.HRef = "www.baidu.com";
}
}