我创建了一个BulletList,并使用以下代码动态填充它。
HtmlGenericControl Link = new HtmlGenericControl("a");
Link.Attributes["href"] = "/ProductDetail/tabid/85/rvdsfpsq/" + Convert.ToString(row["Manufacturer"]) + "/default.aspx";
Link.Attributes["target"] = "_blank";
Link.InnerText = Convert.ToString(row["Manufacturer"]);
StringBuilder generatedHtml = new StringBuilder();
HtmlTextWriter htw = new HtmlTextWriter(new StringWriter(generatedHtml));
Link.RenderControl(htw);
string output = generatedHtml.ToString();
ListItem Item = new ListItem(output);
BulletList1.Items.add(Item);
数据填充数据库中的罚款。我可以渲染" a"标签完美。但是输出的生成如下所示
<li> "<a href="/ProductDetail/tabid/85/rvdsfpsq/2-POWER/default.aspx" target="_blank">2-POWER</a>"</li>
我需要的是
<li><a href="/ProductDetail/tabid/85/rvdsfpsq/2-POWER/default.aspx" target="_blank">2-POWER</a></li>
那么我需要做什么改变才能在没有#34;&#34;的情况下呈现HTML。 qoutes ???
答案 0 :(得分:0)
HtmlGenericControl Link = new HtmlGenericControl("a");
Link.Attributes.Add("href", "/ProductDetail/tabid/85/rvdsfpsq/" + Convert.ToString(row["Manufacturer"]) + "/default.aspx");
Link.Attributes.Add("target", "_blank");
Link.InnerText = Convert.ToString(row["Manufacturer"]);
//create ListItem as HtmlGenericControl.
HtmlGenericControl li = new HtmlGenericControl("li");
li.Controls.Add(Link);
BulletList1.Items.add(li);
这将删除这些引号。