471,321 Members | 2,212 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Format output of dynamic Datagrid columns

J.B
I have a datagrid that will display different datasets, (it runs
different sprocs based on a value in the querystring) but it will
always return 6 columns. The 5th and 6th columns are always Date and
Currency format, all others are strings.

I'd like to build one datagrid to handle this datagrid dynamically. I
have it working now, all except the formatting of the 5th (Date) and
6th (Currency) columns.

Since the headers for those columns will be different depending on the
situation (and the sprocs that is kicked off) I need to format these
columns on the fly.

I have this as my DataGrid:
<ASP:Datagrid id="dgAssetInfo"
runat="server"
AutoGenerateColumns="True"
CellPadding="5"
Font-name="Arial"
Font-size="11px"
OnItemDataBound="dgAssetInfo_ItemDataBound"

<AlternatingItemStyle BackColor = "#DDDDCC" />
<HeaderStyle CssClass="update-header" ForeColor="White" />
<ItemStyle CssClass="text" />
</asp:datagrid>

I am trying to format the Columns using ItemDataBound, basically
saying "make the 5th column look like a date" ({0:D} format).

I experimented with this, but no luck...

Sub dgAssetInfo_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs)

'Format 5th column as Date
E.Item.Cells(4).DataFormatString = {0:D}

'Format 6th column as Currency
E.Item.Cells(5).DataFormatString = {0:C}

End Sub

Can I do this in ItemDataBound? I've looked at the Properties of the
TableCell class but nothing looks like it will allow formatting of
each cell.

Any ideas on how to do this?? Should I be doing it differently (and
no, unfortunately, I can't modify the sprocs to format the data prior
to returning the data)
Nov 17 '05 #1
1 2143
Just an idea,

Why not letting your database formating the output data to date and
Currency format.

Natty Gur[MVP]
Phone Numbers:
Office: +972-(0)9-7740261
Fax: +972-(0)9-7740261
Mobile: +972-(0)58-888377
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by JP011 | last post: by
6 posts views Thread by Hutty | last post: by
7 posts views Thread by CanoeGuy | last post: by

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.