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

Format output of dynamic Datagrid columns

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.