【发布时间】:2010-11-10 08:25:11
【问题描述】:
我想在后面的 C# 代码中生成如下所述的字符串:
<a href="~/Online Exam/Question.aspx?id=1"></a>
我现在使用的代码如下所示:
string url= string.Format("\"~/Online Exam/Question.aspx?id={0}\"", id);
td.Text = "<a href=" + url + ">" + id + "</a>";
但我无法使用上述代码获得所需的输出。请帮我解决这个问题。
【问题讨论】:
-
你得到了什么?代码看起来不错。
-
尽管
">" + id + "</a>"与样本不匹配。 -
输出有什么问题?现在我假设 td 变量是你网页上的一个元素,所以我相信你应该使用 innerhtml 而不是 text。
-
td 是我动态生成的 TableCell。我想要的是在“td.text”中显示一个“id”作为链接,该链接将被定向到“url”并将包含“id”作为查询字符串
标签: c# .net string hyperlink escaping