If there is only one page, then it is fine if we show only Grand Total.
If there is more than one page in the grid, need to show Subtotal ( which is specific to the oage you are in ) and Grand Total , which is going to be for the entire grid.
Can someone help.
Thanks in advance.
10 Answers, 1 is accepted
But is it possible to add a Subtotal and GrandTotal ?
And also..in the fooer total's
if i get negative count i should display as (12345)
Can we do it through this property
FooterAggregateFormatString
and also what format string i need to provide
if(e.Item is GridDataItem)
{
GridDataItem dataItem = e.Item as GridDataItem;
int fieldValue = int.Parse(dataItem["Quantity"].Text);
total+= fieldValue;
}
the int.Parse(dataItem["Quantity"].Text) didn't work for me.
I used a lable inside the template column as mentioned in this forum :
http://www.telerik.com/community/forums/thread/b311D-beecgh.aspx
However it shows incorrect totals when in edit mode.
I want to either show the correct totals or just hide the totals when in edit/insert mode.(I am using in place editing)
In edit mode it does not access to the labels declared in the ItemTemplate.
any suggestions?
Can you please provide the code, which is calculating the totals, as well as the aspx declaration?
Kind regards,
Yavor
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
As a quick follow up on the previous post, since I see that you have posted on another thread with additional information - with inplace editing the itemtemplate will not be visible, and hence the value will not be calculated properly. therefore, you may consider hiding the footer:
.cs
| protected void RadGrid1_PreRender1(object sender, EventArgs e) |
| { |
| if (RadGrid1.EditIndexes.Count > 0) |
| { |
| GridFooterItem footer = (GridFooterItem)RadGrid1.MasterTableView.GetItems(GridItemType.EditItem); |
| footer["TotalColumn"].Visible = false; |
| } |
| } |
I hope this helps.
Sincerely yours,
Yavor
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
protected
void grdTimeSheet_ItemDataBound(object source, Telerik.WebControls.GridItemEventArgs e)
{ //Prepopulate values in the combo on edit
if (e.Item is GridEditableItem && (e.Item as GridEditableItem).IsInEditMode)
{
GridEditableItem editItem = e.Item as GridEditableItem;
RadComboBox comboClient = (RadComboBox)(editItem.FindControl("ddlClient"));
comboClient.Text =
DataBinder.Eval(e.Item.DataItem, "ClientName").ToString();
}
//Render the grid read only if for a past week
else if (e.Item is GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
lblTimeSheetId.Text = item[
"TimeSheetID"].Text;
Label lblSat = (Label)item["Sat"].FindControl("lblSat");
satTotal += Convert.ToDouble(lblSat.Text);
Label lblSun = (Label)item["Sun"].FindControl("lblSun");
sunTotal += Convert.ToDouble(lblSun.Text);
Label lbl = (Label)item["Mon"].FindControl("lblMon");
monTotal += Convert.ToDouble(lbl.Text);
Label lblTue = (Label)item["Tue"].FindControl("lblTue");
tueTotal += Convert.ToDouble(lblTue.Text);
Label lblWed = (Label)item["Wed"].FindControl("lblWed");
wedTotal += Convert.ToDouble(lblWed.Text);
Label lblThur = (Label)item["Thur"].FindControl("lblThur");
thurTotal += Convert.ToDouble(lblThur.Text);
Label lblFri = (Label)item["Fri"].FindControl("lblFri");
friTotal += Convert.ToDouble(lblFri.Text);
}
//show total in the footer
if (e.Item is GridFooterItem)
{
GridFooterItem footerItem = e.Item as GridFooterItem;
footerItem[
"Sat"].Text = satTotal.ToString();
footerItem["Sun"].Text = sunTotal.ToString();
footerItem["Mon"].Text = monTotal.ToString();
footerItem["Tue"].Text = tueTotal.ToString();
footerItem["Wed"].Text = wedTotal.ToString();
footerItem["Thur"].Text = thurTotal.ToString();
footerItem["Fri"].Text = friTotal.ToString();
}
}
the aspx declaration:
<radG:RadGrid ID="grdTimeSheet" runat="server" AllowSorting="True" AutoGenerateColumns="False" DataMember="TimeSheet" EnableAJAX="True" EnableAJAXLoadingTemplate="true" GridLines="None" LoadingTemplateTransparency="50" OnItemCommand="grdTimeSheet_ItemCommand" OnItemDataBound="grdTimeSheet_ItemDataBound" OnNeedDataSource="grdTimeSheet_NeedDataSource" ShowFooter="True" Width="100%">
<MasterTableView AutoGenerateColumns="False" CommandItemDisplay="Top" DataKeyNames="TimeSheetID, TimeSheetRowID" EditMode="InPlace" GridLines="None" ShowFooter="true">
<CommandItemTemplate>
<asp:LinkButton ID="btnSubmit" runat="server" CommandName="Submit" OnClientClick="javascript:return confirm('Submit Timesheet?')" Visible='<%# ViewState["IsCurrentStatus"] %>'><img style="border:0px" alt="" src="RadControls/Grid/Skins/SinglePlus.gif" />Submit TimeSheet</asp:LinkButton>
<asp:LinkButton ID="btnAdd" runat="server" CommandName="InitInsert" Visible='<%# ViewState["IsCurrentStatus"] %>'><img style="border:0px" alt="" src="RadControls/Grid/Skins/Insert.gif" />Add new Record</asp:LinkButton>
</CommandItemTemplate>
<Columns>
<radG:GridEditCommandColumn ButtonType="ImageButton" EditImageUrl="~/RadControls/Grid/Skins/Edit.gif" UniqueName="EditCommandColumn">
<HeaderStyle Width="30px" />
</radG:GridEditCommandColumn>
<radG:GridBoundColumn DataField="TimeSheetId" HeaderText="ID" ReadOnly="True" SortExpression="TimeSheetId" UniqueName="TimeSheetId" Visible="false">
</radG:GridBoundColumn>
<radG:GridTemplateColumn HeaderText="Client" ItemStyle-Width="180px" SortExpression="ClientName" UniqueName="ClientName">
<ItemTemplate>
<%# Eval("ClientName")%>
</ItemTemplate>
<EditItemTemplate>
<radC:RadComboBox ID="ddlClient" runat="server" AutoPostBack="True" DataTextField="ClientName" DataValueField="ClientID" EnableLoadOnDemand="True" ExternalCallBackPage="ComboLookup.aspx" MarkFirstMatch="True" OnSelectedIndexChanged="ddlClient_SelectedIndexChanged" ToolTip="Select Client" Width="175px">
</radC:RadComboBox>
</EditItemTemplate>
</radG:GridTemplateColumn>
<radG:GridTemplateColumn HeaderText="Sat" SortExpression="Sat" UniqueName="Sat">
<ItemTemplate>
<asp:Label ID="lblSat" runat="server" Text='<%# Eval("Sat")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<radI:RadNumericTextBox ID="txtSat" runat="server" NumberFormat-GroupSeparator="" TabIndex="8" Text='<%# Bind( "Sat") %>' Width="40px" MinValue="0" MaxValue="24">
</radI:RadNumericTextBox>
</EditItemTemplate>
</radG:GridTemplateColumn>
<radG:GridTemplateColumn HeaderText="Sun" SortExpression="Sun" UniqueName="Sun">
<ItemTemplate>
<asp:Label ID="lblSun" runat="server" Text='<%# Eval("Sun")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<radI:RadNumericTextBox ID="txtSun" runat="server" MaxValue="24" MinValue="0" NumberFormat-GroupSeparator="" TabIndex="8" Text='<%# Bind( "Sun") %>' Width="40px">
</radI:RadNumericTextBox>
</EditItemTemplate>
</radG:GridTemplateColumn>
<radG:GridTemplateColumn HeaderText="Mon" SortExpression="Mon" UniqueName="Mon">
<ItemTemplate>
<asp:Label ID="lblMon" runat="server" Text='<%# Eval("Mon")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<radI:RadNumericTextBox ID="txtMon" runat="server" MaxValue="24" MinValue="0" NumberFormat-GroupSeparator="" TabIndex="8" Text='<%# Bind( "Mon") %>' Width="40px">
</radI:RadNumericTextBox>
</EditItemTemplate>
</radG:GridTemplateColumn>
<radG:GridTemplateColumn HeaderText="Tue" SortExpression="Tue" UniqueName="Tue">
<ItemTemplate>
<asp:Label ID="lblTue" runat="server" Text='<%# Eval("Tue")%>'></asp:Label>
</ItemTemplate>
< EditItemTemplate>
<radI:RadNumericTextBox ID="txtTue" runat="server" MaxValue="24" MinValue="0" NumberFormat-GroupSeparator="" TabIndex="8" Text='<%# Bind( "Tue") %>' Width="40px">
</radI:RadNumericTextBox>
</EditItemTemplate>
</radG:GridTemplateColumn>
<radG:GridTemplateColumn HeaderText="Wed" SortExpression="Wed" UniqueName="Wed">
<ItemTemplate>
<asp:Label ID="lblWed" runat="server" Text='<%# Eval("Wed")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<radI:RadNumericTextBox ID="txtWed" runat="server" MaxValue="24" MinValue="0" NumberFormat-GroupSeparator="" TabIndex="8" Text='<%# Bind( "Wed") %>' Width="40px">
</radI:RadNumericTextBox>
</EditItemTemplate>
</radG:GridTemplateColumn>
<radG:GridTemplateColumn HeaderText="Thur" SortExpression="Thur" UniqueName="Thur">
<ItemTemplate>
<asp:Label ID="lblThur" runat="server" Text='<%# Eval("Thur")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<radI:RadNumericTextBox ID="txtThur" runat="server" MaxValue="24" MinValue="0" NumberFormat-GroupSeparator="" TabIndex="8" Text='<%# Bind( "Thur") %>' Width="40px">
</radI:RadNumericTextBox>
</EditItemTemplate>
</radG:GridTemplateColumn>
<radG:GridTemplateColumn HeaderText="Fri" SortExpression="Fri" UniqueName="Fri">
<ItemTemplate>
<asp:Label ID="lblFri" runat="server" Text='<%# Eval("Fri")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<radI:RadNumericTextBox ID="txtFri" runat="server" MaxValue="24" MinValue="0" NumberFormat-GroupSeparator="" TabIndex="8" Text='<%# Bind( "Fri") %>' Width="40px">
</radI:RadNumericTextBox>
</EditItemTemplate>
</radG:GridTemplateColumn>
<radG:GridTemplateColumn HeaderText="Total" SortExpression="Total" UniqueName="Total">
<ItemTemplate>
<%
# Eval("Total")%>
</ItemTemplate>
</radG:GridTemplateColumn>
<radG:GridButtonColumn ButtonType="ImageButton" CommandName="Delete" ConfirmText="Delete this Timesheet?"
mageUrl="~/RadControls/Grid/Skins/Delete.gif" Text="Delete" UniqueName="DeleteColumn">
<ItemStyle HorizontalAlign="Center" />
</radG:GridButtonColumn>
</Columns>
<EditFormSettings CaptionDataField="TimeSheetId" CaptionFormatString="Edit TimeSheet {0}"
ColumnNumber="2">
<FormTableItemStyle Wrap="False" />
<FormCaptionStyle CssClass="EditFormHeader" />
<FormMainTableStyle BackColor="White" CellPadding="3" CellSpacing="0" GridLines="Horizontal" Width="100%" />
<FormTableStyle BackColor="White" CellPadding="2" CellSpacing="0" CssClass="module" Height="110px" />
<FormTableAlternatingItemStyle Wrap="False" />
<FormTableButtonRowStyle CssClass="EditFormButtonRow" HorizontalAlign="Right" />
</EditFormSettings>
</MasterTableView>
</radG:RadGrid>
sorry got posted twice .
I Will try hiding the totals as suggested by you.
I have also posted my code in case that helps further.
Cannot convert type 'Telerik.WebControls.GridItem[]' to 'Telerik.WebControls.GridFooterItem'
I tried giving
GridFooterItem
footer = (GridFooterItem)grdTimeSheet.MasterTableView.GetItems(GridItemType.EditItem)[0]
but that gave me this error:Unable to cast object of type 'Telerik.WebControls.GridDataItem' to type 'Telerik.WebControls.GridFooterItem'.
Please suggest
grdTimeSheet.MasterTableView.GetItems(GridItemType.Footer)[0]
sorry for the trouble