views:

78

answers:

4

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" DataFormatString="{0:n2}" />

is there a way i can divide the totaldata by 1048576

any suggestions...??

thanks

+2  A: 

Why don't you divide by 1048576 in the query itself?

Limo Wan Kenobi
A: 

You could use the event OnRowDataBound from the Grid, and there you could do what ever you need.

Oakcool
+1  A: 

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>
Chris Pebble
this is also correct, but as u said doing it in a query is cleaner
+1  A: 

Couple of thoughts:

  1. You could definitely do this in a template field.
  2. Might be easiest to do in the query, just tack on

    select mycolums, totaldata/1048576 as TotalDataInMB From Table

  3. You also could override the OnRowDataBound event and do the calc there.

brendan
Personally, I would use the OnRowDataBound or convert the BoundField to a TemplateField.
Dylan Berry