0

我有一个带有实际上是链接的字符串的数据库字段,假设我有“www.google.com”保存为 nvchar,现在我想从数据表中填充一个网格视图,并将每个字符串显示为一个链接。有什么建议么?

4

2 回答 2

0

您在 gridview 中寻找 HyperLinkField

  <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns ="false">
        <Columns>
             <asp:hyperlinkfield datatextfield="Name"
            datanavigateurlfields="Url"
            datanavigateurlformatstring="{0}"          
            headertext="Url"
            target="_blank" />
        </Columns>
    </asp:GridView>
于 2013-07-27T08:46:07.960 回答
0

您可以在GridView的RowDataBound事件上将这些单元格转换为HyperLinkFields

尝试这个:

protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
  if (e.Row.RowType == DataControlRowType.DataRow)
  {
    HyperLink link = e.Row.Cells[0].Controls[0] as HyperLink;
    if (link != null)
    {
      link.NavigateUrl = link.Text; //"Link Url";
      link.Text = "Click to open this link"; // You may alter the link text.
    }
  }
}
于 2013-07-27T08:47:15.870 回答