473,394 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Datagrid images problem

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
2 1931
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Gilles T. | last post by:
How I can get element ID in the edit mode of datagrid control? If I not in the edit mode, there are no problem. <asp:TemplateColumn ItemStyle-CssClass="grid_column_width_3"...
0
by: Reb | last post by:
I am using a datagrid within another datagrid. My second datagrid is expand/collapse one. I am facing some error. This is my code. ExpandGrid.aspx <form id="Form1" method="post"...
7
by: Bart Schelkens | last post by:
Hi, I have 2 more questions : 1. Can I fill a datagrid by using a DataReader or does it have to be a DataSet or a DataView? 2. In my datagrid I need to display two images and one of does...
9
by: tshad | last post by:
How do I find (and set) a couple of labels in the Footer after a DataGrid is filled? I have a bunch of DataGrids that get displayed nested inside a DataList. The datagrid looks like: ...
16
by: tshad | last post by:
I am trying to center a button in a datagrid column in asp.net and it doesn't seem to work. I have the following: <asp:TemplateColumn ItemStyle-Width="10%" ItemStyle-HorizontalAlign="Center">...
0
by: Raed Sawalha | last post by:
I have aspx page with user control , in the user control i have DataGrid with custom paging the grid is displaying contents of datatable as following schema <xs:element name="id"...
14
by: Brett Sinclair | last post by:
Hello everybody I'm still on the learning curve here...and from what I read, I created inherited datagrid class so I could have icons, combobox...etc in the columns of my datagrid. The grid...
4
by: Pawel | last post by:
Hello I've a problem with DataGrid and Icon. Incons are in DataGrid's cells next to the other data. And now. When i cklick this icon i want to change icon without reload site. How to do this?...
0
by: rupalirane07 | last post by:
Both grids displays fine. But the problem is only parent datagrid sorting works fine but when i clik on child datagrid for sorting it gives me error: NullReferenceException error Any...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.