Click here to Skip to main content
15,890,825 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hey guys I am getting above error. Please see in my code below & suggest me what I was doing wrong :

ASP.NET
<div id="gallery">
<div id="div_images"   runat="server"> </div>
</div>

C#
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
        {

        }
    }

I tried it from last days but doesn't get the solution. Any suggestion really appreciate !
Posted
Updated 13-May-13 23:40pm
v4
Comments
vijay__p 13-May-13 8:58am    
What error are you getting ?
Mas11 13-May-13 9:17am    
Cannot get inner content of div_images because the contents are not literal
ZurdoDev 13-May-13 10:26am    
You need to reply to the comment so that the user who made the comment is notified. Please do not add a new comment to your own question.

Follow how can get innerhtml of a server side element with c# (with another server-side controls inside)[^].
Quote:
You can't invoke InnerHtml on a div unless its contents are literal (i.e. there aren't server controls contained inside it). But you can force it to render to a string by doing something like this:

C#
var sb = new StringBuilder();
mainDiv.RenderControl(new HtmlTextWriter(new StringWriter(sb)));

string s = sb.ToString();
 
Share this answer
 
Comments
Mas11 14-May-13 5:44am    
Can you please write code as per my code scenario, because I tried your solution but doesn't reach to run it.
Hey Guys I have Solved this. See my solution below !
C#
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
    {

    }
 
Share this answer
 
v2
Comments
Member 10507986 10-Feb-14 3:17am    
Thanks it's working for me..Shraddha Singh
Mas11 12-Feb-14 9:14am    
Your Welcome :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900