繁体   English   中英

无法获取 div_images 的内部内容,因为内容不是文字

[英]Cannot get inner content of div_images because the contents are not literal

我收到以下错误。 请在下面的代码中查看并建议我做错了什么。

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
    {

    }
}

我从最后几天开始尝试,但没有得到解决方案。 任何建议真的很感激。

我已经解决了这个问题:

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
    {

    }

您不应在呈现控件后使用 innerHtml。 改为使用RenderControl ,如下所述:

http://forums.asp.net/t/1168614.aspx

字符串值 = ((Literal)(cell.Controls[0])).Text

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM