By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,932 Members | 1,486 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,932 IT Pros & Developers. It's quick & easy.

Datagrid images problem

P: n/a
I am building a website using C#, asp.net and SqlServer. I need to
store a lot of images in my database. I need to store thumbnails but
also larger pictures(when user clicks thumbnails a larger picture is
displayed). For doing that I was told to store only the URL's. My
problem now is how to display these images. I know that the tag <img>
is recognised by the datagrid and allow an easy display of a picture.
But I don't think storing the url with this tag is a good way for
doing it. And also how can I display several pictures on a same row?
Any help, articles, documentation would be really good.
Thanks
Celine
Nov 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi Celine,
Are you storing the images in the DB or not?

If you are then you need to retrieve them and show them, this is not a
trivial thing.

If you are only storing the URL then it's very easy, it all depend of how
you define your datagrid. below you will find an piece of code what shows
you how to do it.

in the aspx file ( declaration of the datagrid ):
<asp:datagrid id=recordgrid runat="server" ShowHeader="false"
autoGenerateColumns="False" >
<SelectedItemStyle CssClass="resultrow">
</SelectedItemStyle>
<itemstyle CssClass="listrecordrow" Width="22px" />
<columns>
<asp:templatecolumn ItemStyle-Height="22" ItemStyle-VerticalAlign="Middle"
ItemStyle-Width="25" ItemStyle-HorizontalAlign="Center" >
<itemtemplate>
<img src="<%# ((DataRowView)Container.DataItem)["ImageUrl"] %>" >
</itemtemplate>
</asp:templatecolumn>
</columns>
</asp:datagrid>
As you can see all you have to do is using binding set the value of the src
property of the img tag

then in the code behind you can do:

recordgrid.DataSource = GenerateDataSource( ) ;
recordgrid.DataBind();
Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Celine" <sq*****@yahoo.fr> wrote in message
news:f3*************************@posting.google.co m...
I am building a website using C#, asp.net and SqlServer. I need to
store a lot of images in my database. I need to store thumbnails but
also larger pictures(when user clicks thumbnails a larger picture is
displayed). For doing that I was told to store only the URL's. My
problem now is how to display these images. I know that the tag <img>
is recognised by the datagrid and allow an easy display of a picture.
But I don't think storing the url with this tag is a good way for
doing it. And also how can I display several pictures on a same row?
Any help, articles, documentation would be really good.
Thanks
Celine

Nov 16 '05 #2

P: n/a
Thanks for your help.
Yes, I store only the URLs in my database.
I didn't managed to make your code work but I changed some of it to
make it work. Here is the code I used:
<asp:datagrid id="recordgrid" runat="server" ShowHeader="false"
autoGenerateColumns="False">
<SelectedItemStyle CssClass="resultrow"></SelectedItemStyle>
<itemstyle CssClass="listrecordrow" Width="22px" />
<columns>
<asp:templatecolumn ItemStyle-Height="22"
ItemStyle-VerticalAlign="Middle" ItemStyle-Width="25"
ItemStyle-HorizontalAlign="Center">
<itemtemplate>
<img src='<%# DataBinder.Eval(Container.DataItem, "PhotoName",
"{0:c}") %>' >
</itemtemplate>
</asp:templatecolumn>
</columns>
</asp:datagrid>

Sorry to bother but I still got 2 questions. Is it possible to convert
this column to an hyperlink column so that when the user clicks the
picture a larger one is displayed?
And is it possible to display several thumbnails on the same row(i.e 5
thumbnails per row)instead of having each of them on different rows?
Thanks
Celine

"Ignacio Machin \( .NET/ C# MVP \)" <ignacio.machin AT dot.state.fl.us> wrote in message news:<u#*************@TK2MSFTNGP10.phx.gbl>...
Hi Celine,
Are you storing the images in the DB or not?

If you are then you need to retrieve them and show them, this is not a
trivial thing.

If you are only storing the URL then it's very easy, it all depend of how
you define your datagrid. below you will find an piece of code what shows
you how to do it.

in the aspx file ( declaration of the datagrid ):
<asp:datagrid id=recordgrid runat="server" ShowHeader="false"
autoGenerateColumns="False" >
<SelectedItemStyle CssClass="resultrow">
</SelectedItemStyle>
<itemstyle CssClass="listrecordrow" Width="22px" />
<columns>
<asp:templatecolumn ItemStyle-Height="22" ItemStyle-VerticalAlign="Middle"
ItemStyle-Width="25" ItemStyle-HorizontalAlign="Center" >
<itemtemplate>
<img src="<%# ((DataRowView)Container.DataItem)["ImageUrl"] %>" >
</itemtemplate>
</asp:templatecolumn>
</columns>
</asp:datagrid>
As you can see all you have to do is using binding set the value of the src
property of the img tag

then in the code behind you can do:

recordgrid.DataSource = GenerateDataSource( ) ;
recordgrid.DataBind();
Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Celine" <sq*****@yahoo.fr> wrote in message
news:f3*************************@posting.google.co m...
I am building a website using C#, asp.net and SqlServer. I need to
store a lot of images in my database. I need to store thumbnails but
also larger pictures(when user clicks thumbnails a larger picture is
displayed). For doing that I was told to store only the URL's. My
problem now is how to display these images. I know that the tag <img>
is recognised by the datagrid and allow an easy display of a picture.
But I don't think storing the url with this tag is a good way for
doing it. And also how can I display several pictures on a same row?
Any help, articles, documentation would be really good.
Thanks
Celine

Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.