Click here to Skip to main content
12,945,706 members (42,707 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I am using FileUpload control, after submit of uploadclick button..the file name is saved in database.. and then I am reteriveing it in gridview ... where I bind image button?

Problem is that SubmitQuery is display instead of image plz help...

<asp:imagebutton id="ImageButton1" imageurl="<%# Eval(" picture=") %>" commandname="Image" xmlns:asp="#unknown" />
Posted 22-Aug-10 18:44pm
Updated 26-Aug-10 0:32am
GPUToaster 23-Aug-10 2:18am
use http handlers for specific urls!!
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I am not sure whether I understood your problem correctly. Assuming that you have the following situation:

1. You are uploading the file successfully using the FileUpload control.
2. You are able to save file data into database (Say, file name, size etc)

Now while you are trying to display the image button in the Grid View, you are trying to show the images as the Image button's background. But, for some reason, the image is not being shown for the image buttons.

If the above understanding is correct, here is what you need to work on:

An important issue is, where are you storing the file content. In the database? Or, in the file system.

Assumption1 : File content is stored the file system

--If you are storing the file content in the file system, then, either in the "picture" property of your object should have a correct URL value that points to the image within the web application folder, or, you should use a method that takes the "picture" property value as parameter and returns the relative URL of the image.

For example, suppose you storing the image "profile.jpg" as "/images/profile.jpg" within the web application folder. so, either the "picture" property of your object should contain the URL "~/images/profile.jpg" or you can call a method GetImageUrl() as follows:

Imageurl="<%# GetImageUrl(Eval ("picture")) %>"

where the method willl take just the "profile.jpg" as parameter and will return "~/images/profile.jpg"

Good luck

Assumption2 : File content is stored in the database

--Well, in this case, you have to do a bit more work. You have to provide the ImageUrl property value as described above and then you have to create an HttpHandler that would handle any URL that has image file extension in the request file name and read and writes the file content in the output stream.

See an example HttpHandler here :[^]
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

you have to add temporary folder in your solution and on RowDataBound Event you have to get byte[] data which could be stored in HiddenField like

<asp:hiddenfield id="hdfData" value="<%# Eval("ImageData")%>" xmlns:asp="#unknown" />

which is in gridview itemtemplate and retrieve in _RowDataBound Function.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

you can add image folder in solution explorer.. with implementing math function in code behind class..

after that :

<asp:imagebutton id="ImageButton1" runat="server" imageurl="<%# "~/images/" + Eval("picture")%>" width="100px" height="100px" xmlns:asp="#unknown" />;
Christian Graus 26-Aug-10 4:10am
What on earth is the point of saying this when someone else has already given an extensive answer ?

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 4,899
CHill60 3,180
Maciej Los 2,453
Jochen Arndt 1,910
ppolymorphe 1,785

Advertise | Privacy | Mobile
Web02 | 2.8.170518.1 | Last Updated 12 Oct 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100