Loading ...

Modifying Data in a asp:Boundfield DataField statement

Who is online?  0 guests and 0 members
home  »  forums   »  asp.net topics   »  getting started / general asp.net   » Modifying Data in a asp:Boundfield DataField statement

Modifying Data in a asp:Boundfield DataField statement

Posts under the topic: Modifying Data in a asp:Boundfield DataField statement

Posted: 6/27/2011

Lurker 30  points  Lurker
  • Joined on: 6/27/2011
  • Posts: 6

Hello,

 

I currently have the following code:

        <Columns>

            <asp:BoundField DataField="groupName" HeaderText="Area" >

            <ItemStyle HorizontalAlign="Center"></ItemStyle>

                </asp:BoundField>

            <asp:BoundField DataField="totalCount" HeaderText="Total PCs" >

            <ItemStyle HorizontalAlign="Center"></ItemStyle>

                </asp:BoundField>

            <asp:BoundField DataField="availableCount" HeaderText="Available" >

            <ItemStyle HorizontalAlign="Center"></ItemStyle>

                </asp:BoundField>

            <asp:BoundField DataField="offCount" HeaderText="Offline" >

            <ItemStyle HorizontalAlign="Center"></ItemStyle>

                </asp:BoundField>

            <asp:BoundField DataField="inUseCount" HeaderText="In Use" >

            <ItemStyle HorizontalAlign="Center"></ItemStyle>

                </asp:BoundField>

         </Columns>

    </asp:GridView>

 

I want to modify the "inUseCount" data that is retreved to reflect a true count of machines that is actually in use. (For some reason the "inUseCount" data is calculated by the server like: inUseCount = totalCount - availableCount).

Ultimately I would like to modify it like: newInUseCount = inUseCount - offCount -- to reflect the number of machines that are online and being used by a person, and not combined with the number of machines that are off as well.

How would I modify this data and display it properly in the GridView?

 

Thanks for your assistance!

Robert

 

 

 


Posted: 6/27/2011

Starter 727  points  Starter
  • Joined on: 6/6/2011
  • Posts: 74

Hi Robert,

Try to use template field, like this:

<asp:TemplateField HeaderText="New Custom Count">
 <ItemTemplate>
      <asp:Label runat="server" Text='<%# Eval("inUseCount") - Eval("offCount") %>' />
 </ItemTemplate>
</asp:TemplateField>

Best Regards,

Gjorgji


Posted: 6/27/2011

Lurker 30  points  Lurker
  • Joined on: 6/27/2011
  • Posts: 6

Thanks Gjorgji for the response!  I made the changes however now I am getting a new error: CS0019: Operator '-' cannot be applied to operands of type 'object' and 'object'

The type of value returned should already be an integer, so I am a little confused as to why it is saying it's an object... any suggestions?


Posted: 6/27/2011

Starter 727  points  Starter
  • Joined on: 6/6/2011
  • Posts: 74
  Answered

Hi Robert,

Try to convert them to int like this:

<asp:Label runat="server"Text='<%# (int)Eval("inUseCount") - (int)Eval("offCount") %>' />

Best Regards,

Gjorgji


Posted: 6/27/2011

Lurker 30  points  Lurker
  • Joined on: 6/27/2011
  • Posts: 6

That works perfectly!  Thanks so much for taking the time to answer my post!!!

Robert


Page 1 of 1 (5 items)