【问题标题】:Add hyperlinks to datatable将超链接添加到数据表
【发布时间】:2009-10-12 19:09:17
【问题描述】:

我想将超链接动态添加到我的数据表中特定列的单元格。目前我的代码只显示文本。

这是我的代码:

SqlConnection conn = null;
string sSQL = "";
string connString = "Datasourceetc";

sSQL = "SELECT TEST_ID FROM TEST_TABLE";

SqlDataAdapter sda = new SqlDataAdapter(sSQL, conn);

DataTable dt = new DataTable();

sda.Fill(dt);

foreach (DataRow row in dt.Rows)
{
  row["TEST_ID"] = "<a href='www.google.com'>Google</a>"; //<----I only see the text!
}

GridView1.DataSource = dt;

GridView1.DataBind();

谢谢

【问题讨论】:

  • 如果您在浏览器中执行“查看源代码”,您会看到什么?
  • 为什么不在您的 GridView 列部分中放置一个 HyperlinkField?
  • @David - 对于显示的单个 块:<a href='www.google.com'>Google</a>
  • @pjabbott - 如果我想将“TEST_ID”列中的所有值更改为指向 google.com 的链接,我该怎么做?
  • 您找到解决方案了吗?因为我正在努力实现同样的目标

标签: c# datatable hyperlink


【解决方案1】:

如果您通过 asp:BoundField 执行此操作,您需要将 HtmlEncode property 设置为 false

【讨论】:

    猜你喜欢
    相关资源
    最近更新 更多
    热门标签