I have a query which returns me the total data in bytes...
is there a way i can change this value to MB in the bound field
my bound field is :
<asp:BoundField DataField="totaldata" HeaderText="Total Data"
ReadOnly="True" SortExpression="totaldata" DataFor开发者_如何学CmatString="{0:n2}" />
is there a way i can divide the totaldata by 1048576
any suggestions...??
thanks
Why don't you divide by 1048576 in the query itself?
Doing it in the database as Limo Wan Kenobi suggested is probably the cleanest way to do it.
However, if that's not an option, another way to do it would be to use a TemplateField instead of a Boundfield:
<asp:TemplateField>
<ItemTemplate>
<asp:Label runat="server" id="lblMB" text='<%# Math.Round(eval("totaldata") / 1024)) %>' />
</ItemTemplate>
</asp:TemplateField>
Couple of thoughts:
- You could definitely do this in a template field.
Might be easiest to do in the query, just tack on
select mycolums, totaldata/1048576 as TotalDataInMB From Table
You also could override the OnRowDataBound event and do the calc there.
You could use the event OnRowDataBound from the Grid, and there you could do what ever you need.
精彩评论