Reputation: 453
I pull the data out of my database and put it in a DataSet through SqlAdapted and then DataBind it.
My question is how can I change the way data is presented in the table?
Example: Some should have 2 digits after decimal and some should have 3 etc. Example: Some should be right justified whereas some should be centered?
Upvotes: 0
Views: 99
Reputation: 630
When you build your Gridview, you can assign items as <asp:BoundFields>
, instead of using "AutoGenerateColumns". This gives you more control, for example:
<asp:BoundField DataField="DateLastContacted" HeaderText="Contacted" SortExpression="DateLastContacted" ItemStyle-CssClass="resultscell" HeaderStyle-CssClass="resultsheader" ItemStyle-HorizontalAlign="Center" DataFormatString="{0:dd MMM yyy}" NullDisplayText="N/A" />
You can use ItemStyle-HorizontalAlign="Center"
for your alignment, and use DataFormatString="{0:N2}"
to specify decimals, see here:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfield.dataformatstring.aspx
HTH
Upvotes: 1