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

StackOverflow https://stackoverflow.com/questions/16522498

  •  21-04-2022
  •  | 
  •  

Вопрос

I am getting the error below. Please see in my code below & suggest me what I was done wrong.

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();
    }
}

Code :

 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
    {

    }
}

I tried it from last days but doesn't get the solution. Any suggestion really appreciate.

Это было полезно?

Решение

I have solved this:

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
    {

    }

Другие советы

You should not use innerHtml after the control was rendered. use RenderControl instead, as explained here:

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

string value = ((Literal)(cell.Controls[0])).Text

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top