Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
I have a datagrid that displays the data I want it to. The problem is that I am trying to format the last column in the datagrid as currency and it is not allowing me to. The columns in the datagrid are generated automatically at runtime and the connection to the database was created in VB.NET code. There are 9 columns counting from 0, when I do a column count it returns the number of 0 which is not the case. Thus I am unable to format the last column in the datagrid as currency. Any help with this problem would be greatly appreiciated.
Posted
I have a datagrid that displays the data I want it to. The problem is that I am trying to format the last column in the datagrid as currency and it is not allowing me to. The columns in the datagrid are generated automatically at runtime and the connection to the database was created in VB.NET code. There are 9 columns counting from 0' date=' when I do a column count it returns the number of 0 which is not the case. Thus I am unable to format the last column in the datagrid as currency. Any help with this problem would be greatly appreiciated.[/quote']

I think if you do the format in the datagrid's prerender event, you should be fine!

Joe Mamma

Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized.

Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.

Posted

Set AutoGenerateColumns property to "False" and create your own BoundColumn subcontrol to lay out your grid. This will allow you to use the DataFormatString property. Below is an example for you to review.

 

 

 

<asp:DataGrid id="DataGrid1" BorderColor="gray" runat="server"

AutoGenerateColumns="false" CellPadding="2" Font-Name="Arial" Font-Size="10pt"

HeaderStyle-BackColor="lightgreen"

AllowPaging="True"

PageSize="4"

PagerStyle-Mode="NumericPages"

OnPageIndexChanged="DataGrid1_PageIndexChanged">

<Columns>

<asp:BoundColumn HeaderText="Customer#" DataField="CustNum"

ItemStyle-HorizontalAlign="Center"/>

<asp:BoundColumn HeaderText="Last Name" DataField="LastName"/>

<asp:BoundColumn HeaderText="Order#" DataField="OrdNum"

ItemStyle-HorizontalAlign="Center"/>

<asp:BoundColumn HeaderText="Order Date" DataField="OrderDate"

DataFormatString="{0:MM-dd-yy}" ItemStyle-HorizontalAlign="Center"/>

<asp:BoundColumn HeaderText="Item Description" DataField="Description"/>

<asp:BoundColumn HeaderText="Quantity" DataField="LIQuantity"

ItemStyle-HorizontalAlign="Center"/>

<asp:BoundColumn HeaderText="Unit Price" DataField="Price"

DataFormatString="{0:C}" ItemStyle-HorizontalAlign="Right"/>

<asp:BoundColumn HeaderText="Ext Price" DataField="ExtPrice"

DataFormatString="{0:C}" ItemStyle-HorizontalAlign="Right"/>

</Columns>

</asp:DataGrid>

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...