Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to retrive image and data from sql and dispaly in datalist one below the other

i am able to retrive images from sql to datalist but not able to retrive data and display image n data in datalist please check this link for image and help me thanks in advance

http://img714.imageshack.us/img714/4229/datalistimageswittag.jpg

image alone can be retrived which i can do but i am not understanding how to get data also lik prodname n prodcost

everything is working fine but i am getting error like images are not selecting from the table it is jus showing same image to all the quries and code is:

<asp:DataList ID="DataList1" runat="server" RepeatColumns="3" RepeatDirection="Horizontal"
Width="100%" BorderColor="#336699" BorderStyle="Solid" BorderWidth="2px">
<itemtemplate>
<asp:Image ID="Image1" runat="server" ImageUrl='<%# "ShowImageb.ashx?bid=" + Eval("bid") %>' />



<asp:Label ID="Label1" runat="server" Text='<%# Eval("pid") %>'>

<itemstyle horizontalalign="Center" verticalalign="Top">


can u plz check with the error and tel me wher to correct thanks for the support
Posted
Updated 18-Apr-12 23:16pm
v2

You can't bind images directly to DataList, instead you could do something like this:

XML
<asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1">
    <ItemTemplate>
        <asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("ImageID", "ImageHandler.ashx?imgId={0}") %>' />
        <br />
        <asp:Label ID="Label1" runat="server" Text='<%# Eval("Data") %>'></asp:Label>
    </ItemTemplate>
</asp:DataList>


Then create a generic handler ImageHandler.ashx and in it's codebehind use imgId parameter from query string to serve the image from database.
 
Share this answer
 
Comments
karthikh87 12-Apr-12 0:22am    
yup i did same thing.. i mean using generic handler i got image to data list n i wanted to get few lines of words below the image so is it possible to bind data also below the image or i have to use any other like gridview etc..??
sjelen 12-Apr-12 7:20am    
In the example above ItemTemplate has an Image and a Label below it. You can bind your text to it. It doesn't have to be a Label, depends how you want it formatted.
karthikh87 12-Apr-12 13:06pm    
Thnak you sjelen..
karthikh87 19-Apr-12 5:17am    
i have little doubt can u plz check what is the error and tell me my friend
An image stored in a database is the same as any other field

SELECT image, field1, field2,...
FROM table


This resultset can be bound to the DataList the same as described in hundreds of resources.

What part are you having difficulty with?
 
Share this answer
 
Comments
sjelen 11-Apr-12 12:15pm    
How would you bind an image to DataList?
[no name] 11-Apr-12 12:28pm    
Why are you asking a question for which you have already posted the answer to?

"as described in hundreds of resources." You have just added one more.
sjelen 11-Apr-12 13:34pm    
First, selecting actual image data is not necessary for binding to DataList - only an id of image. The way you wrote select might lead him to do just that and in this case image data would only create unnecessary SQL traffic.
Second, "as described in hundreds of resources." is not very helpfull to an obvious beginner. You could have provided at least a link to one of those resources.
No hard filings :)
[no name] 11-Apr-12 14:16pm    
In my reference field1 or field2 could also be an image, or other binary data. The question was vague at best and without specific details a specific answer can't be given.

"Not very helpful to an obvious beginner". And you were ever so helpful to mention HTTPHandler without providing any descriptions, instruction, or references that such a beginner would even be able to understand what you have meant.

Think before responding or answering future question or comments.
sjelen 12-Apr-12 7:15am    
No offense, but "use HTTPHandler" is a bit more direct then "as described in hundreds of resources."

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