Wednesday, November 2, 2011

How to refresh a ASPxGridView summary value on the client side

The ASPxGridView is a server side control, so it renders on the server side.

If you know how the summary value should be changed using the client side code, you need to do the following:

1) add the ASPxLabel to the column's FooterTemplate container and set its ClientInstanceName to a some value, for example, lblFooter;
2) use the lblFooter.SetText('some text') to change the displayed summary value.

Here is some sample code:

[ASPx]

<dx:GridViewDataTextColumn FieldName="CategoryID" ReadOnly="True" VisibleIndex="1">
<EditFormSettings Visible="False" />
<FooterTemplate>
<dx:ASPxLabel ID="ASPxLabel1" ClientInstanceName ="lblFooter" runat="server"
Text="<%# GetSummaryValue(Container)%>">
</dx:ASPxLabel>
</FooterTemplate>
</dx:GridViewDataTextColumn>
....


[C#]



protected string GetSummaryValue(GridViewFooterCellTemplateContainer container) {
ASPxGridView gridView = container.Grid;
GridViewDataColumn column = container.Column as GridViewDataColumn;
if(column == null)
return string.Empty;
for(int i = 0; i < gridView.TotalSummary.Count; i ++)
if(gridView.TotalSummary[i].FieldName == column.FieldName) {
return gridView.GetTotalSummaryValue(gridView.TotalSummary[i]).ToString();
}
return string.Empty;
}

No comments :

Post a Comment