i 使用 UrlDecode () 和 kill () 方法来避免例外 。 但我还是有错误 。
<asp:Repeater ID="rptProducts" runat="server">
<ItemTemplate>
<div>
<%# Eval("ProductName")%>
</div>
<div>
<%# kill(Server.UrlDecode(IsNullControl(Eval("ProductFeature").ToString())))%>
</div>
</ItemTemplate>
</asp:Repeater>
try
{
ProductsDataContext pdc = new ProductsDataContext();
var query = from p in pdc.Products
select p;
rptProducts.DataSource = query;
rptProducts.DataBind();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
public static string kill(string val)
{
val = val.Replace("<ul>", " ");
val = val.Replace("<li>", " ");
val = val.Replace("</li>", "<br/>");
val = val.Replace("</ul>", " ");
return val.ToString();
}
public static string IsNullControl(string val)
{
string space = " ";
if (string.IsNullOrEmpty(val))
{
val = space;
}
return space;
}