Wrox Programmer Forums
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 28th, 2005, 01:37 PM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
Default Can a Datagrid...

One of the reasons I frequently don't use the datagrid control, opting instead to programetically create an html table, is because the datagrid doesn't seem to be able to do anything with the data other than display it, page through it, and sometimes accept edits.

For example, I have a field in a datatable called txtImage, which holds the location and filename of an image as a varchar. It would be nice, instead of displaying the text of the folder and image name, to display a thumbnail of an image. I am not able to store the actual image in the database for unrelated business reasons.

Does anyone know of a way to implement this in a datagrid, or does this have to be generated manually?

Thanks as always for your feedback.

Aaron

 
Old June 28th, 2005, 02:15 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You should convert your DataGrid's columns to a TemplateColumn. Then you can dump whatever you see fit in the ItemTemplate, like an Image control that gets its ImageUrl from the data source:

<asp:TemplateColumn HeaderText="Image">
  <ItemTemplate>
    <asp:Image id="imgWhatever" runat="server" ImageUrl='<%#DataBinder.Eval(Container.DataItem, "Image")%>' />
  </ItemTemplate>
</asp:TemplateColumn>

Does this help?

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old June 29th, 2005, 01:30 PM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Imar,

Could you point me to more information on the TemplateColumn control?

Is this the kind of thing where I could also manipulate data before I display it (i.e. use the toShortDateString method on a DateTime field)?

Thanks.

Aaron

 
Old June 29th, 2005, 01:38 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Yes, you can. You even have a few options.

First of all, you can just call methods in the databinding, formatting you code directly.

Another alternative is to use ItemCreated or ItemDataBound that fire for each item. Inside those methods, you can retrieve the bound data, and format it in any way you like.

If you search Google for TemplateColumn DataGrid you'll find lots of useful articles.

Here are a few:

http://msdn.microsoft.com/library/de...classtopic.asp

http://msdn.microsoft.com/library/de...vercontrol.asp

http://aspnet.4guysfromrolla.com/articles/040502-1.aspx

The last one might take some time; it's part 1 of an 18 part series that gives you a lot of information about the DataGrid.

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom paging in Datagrid with datagrid page count madhusrp ASP.NET 1.0 and 1.1 Professional 12 June 2nd, 2008 01:15 PM
User COntrol Datagrid inside datagrid rodmcleay ASP.NET 1.0 and 1.1 Professional 3 April 14th, 2007 10:11 AM
Creating DataGrid In Repeater/DataGrid liduwan ASP.NET 1.0 and 1.1 Professional 9 March 6th, 2007 03:31 PM
datagrid ajaidass ADO.NET 2 March 1st, 2007 05:36 PM
Need help regarding datagrid ngsharmila .NET Framework 1.x 1 February 1st, 2006 12:55 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.