开发者

modify data in bound field and template field

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:

  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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜