GridView中的超级链接HyperLinkField

第一种方法:

<asp:HyperLinkField DataNavigateUrlFields="stu"
                    DataNavigateUrlFormatString="xx.aspx?stu={0}"
                     HeaderText="更新" Text="更新" >
                    <HeaderStyle HorizontalAlign="Center" />
                    <ItemStyle HorizontalAlign="Center" />
</asp:HyperLinkField>

DataNavigateUrlFields,也就是gridview中的字段,DataNavigateUrlFormatString,就可以对字符串进行编辑

DataNavigateUrlFields,也就可以传递多个参数

第二种方法

 <asp:TemplateField HeaderText="更新" Visible="true" HeaderStyle-HorizontalAlign = "Center"  ItemStyle-HorizontalAlign="Center">
         <ItemTemplate>
               <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='' Text="更新"></asp:HyperLink>
         </ItemTemplate>

<HeaderStyle HorizontalAlign="Center"></HeaderStyle>

<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateField>

TemplateField 模板列要在RowDataBound进行绑定

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
     {
       if (e.Row.RowType == DataControlRowType.DataRow)
         {
             //模板列

             ((HyperLink)e.Row.Cells[10].FindControl("HyperLink1")).NavigateUrl = "xx.aspx?stu=" + Server.UrlEncode(e.Row.Cells[0].Text.Trim());

         }

     }

你可能感兴趣的:(object,server,asp,Hyperlink)