嘿伙计们我犯了错误。请参阅下面的代码&建议我做错了什么:
HTML:
string ProductImages = string.Empty;
string str_query = string.Empty;
DataTable dt_Common = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bind_images();
}
}
代码:
private void bind_images()
{
if (Request.QueryString["id"] != null)
{
str_query = "select top(5) image from tbl_product_images where productinfo_id='" + Request.QueryString["id"].ToString() + "'";
dt_Common = new CommonClass().bind_department(str_query);
if (dt_Common.Rows.Count> 0)
{
for (int i = 0; i < dt_Common.Rows.Count; i++)
{
div_images.InnerHtml += "<a class=\"activeborder\" data-image=" + dt_Common.Rows[i]["image"] + " data-zoom-image=" + dt_Common.Rows[i]["image"] + "><img src=" + dt_Common.Rows[i]["image"] + " /></a>"; // Getting error in this line.
}
}
}
else
{
}
}
我从前几天开始尝试,但没有得到解决方案。任何建议都非常感谢。
答案 0 :(得分:4)
嘿伙计们我解决了这个问题。请参阅下面的解决方案!
StringBuilder _StrB = new StringBuilder();
if (Request.QueryString["id"] != null)
{
str_query = "select top(5) image from tbl_product_images where productinfo_id='" + Request.QueryString["id"].ToString() + "'";
dt_Common = new CommonClass().bind_department(str_query);
if (dt_Common.Rows.Count> 0)
{
for (int i = 0; i < dt_Common.Rows.Count; i++)
{
image.Src = dt_Common.Rows[i]["image"].ToString().Replace("~", "..");
_StrB.Append("<a id=" + i + " class=\"activeborder\" data-image=" + dt_Common.Rows[i]["image"].ToString() + " data-zoom-image=" + dt_Common.Rows[i]["image"].ToString() + "><img src=" + dt_Common.Rows[i]["image"].ToString() + " /></a>");
}
}
string AllHTMLImages = _StrB.ToString().Replace("~", "..");
div_images.InnerHtml = AllHTMLImages;
}
else
{
}
答案 1 :(得分:2)
渲染控件后不应使用innerHtml。请改用RenderControl
,如下所述:
答案 2 :(得分:0)
string value =((Literal)(cell.Controls [0]))。Text