Posted: 6/27/2011
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" >
<asp:BoundField DataField="availableCount" HeaderText="Available" >
<asp:BoundField DataField="offCount" HeaderText="Offline" >
<asp:BoundField DataField="inUseCount" HeaderText="In Use" >
</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
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
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?
Try to convert them to int like this:
<asp:Label runat="server"Text='<%# (int)Eval("inUseCount") - (int)Eval("offCount") %>' />
That works perfectly! Thanks so much for taking the time to answer my post!!!