J
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:
<ASPatagrid 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} 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}
'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)
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:
<ASPatagrid 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} 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}
'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)