Click here to Skip to main content
15,893,814 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi Folks,

Have a weird ask.
I have 4 sections in a web page, out of which one section is an image.
A SQL table having 5 columns is prepared, corresponding to the 4 sections of the web page.
Even the image name is stored in one of the column of the table.

My requirement is how to apply the image name from the SQL table to the actual image inserted in the code.

Below is my table structure:

SQL
ErrorCode   Section1    Section2                Section3    Section4    
1001        Sorry       You don't have access   Pic1.jpg    Contact HelpDesk


And here is my front end stuffs:

XML
<div id="First">
    <asp:Label ID="Section1" runat="server" CssClass="FirstLabelStyle">
    </asp:Label>
    </div>
  
    <div id="Second">
    <asp:Label ID="Section2" runat="server" CssClass="NewerLabelStyle">
    </asp:Label>
    </div>
   
    <div id="Third">
    <asp:Image ID="FirstImage" ImageUrl="~/Images/RequestAccess.png" runat="server" />
    </div>
   
    <div id="Fourth">
    <asp:Label ID="Section4" runat="server" CssClass="NewerLabelStyle">
    </asp:Label>
    </div>


Below is my C# code:

C#
protected void Page_Load(object sender, EventArgs e)
{
        if (!string.IsNullOrEmpty(Request.QueryString["ErrorCode"]))
        {
            int errorcode = Convert.ToInt32(Request.QueryString["ErrorCode"]);

            DataTable dtErrorPage = DomainBL.GetData("ErrorPage");

            if (errorcode == 1001)
            {
                Section1.Text = dtErrorPage.Rows[0][1].ToString();
                Section2.Text = dtErrorPage.Rows[0][2].ToString();
                Section4.Text = dtErrorPage.Rows[0][4].ToString();
            }
        }
}


I guess I have made my question clear. I just wana know how to apply the name of the
image as 'Pic1.jpg' so that when its deployed in the server, IIS retains the same name.
I know I m missing something, not able to re-collect it.
Any pointers will be highly appreicated.

-Anurag
Posted
v2

Hello Anurag,

You can do this in tow ways.

  1. Via HTTPHandler[^.
  2. Simple binding
    VB
    Image.Imageurl=Server.MapPath("~/Images/" + strPathFromDb

Regards,
 
Share this answer
 
Comments
Anurag Sinha V 20-Mar-13 11:45am    
Thank you Prasad..i will try this and will update it over here too...

-Anurag
HI folks..

thought sm stuffs and took help from the above solution and have finally solved this issue.

I was missing a stuff.
Have kept the image name in the Db and instead of assigning the ImageUrl in the .aspx page, I am assigning it in the aspx.cs page.Something like below:

C#
ImageName.ImageUrl="~/Images/"dt.Rows[0][3]"";

The 3rd column in the zeroth row has the image name embedded in it.

It finally solved my problem.

-Regards
Anurag
 
Share this answer
 

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