Skip to content

integrationvault/aspxgridview-how-to-show-the-live-data-without-refreshing-the-grid-using-webmethods-t530119

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Files to look at:

ASPxGridView - How to show the live data without refreshing the grid (using WebMethods)

[Run Online]

This example demonstrates how to update data only for several (or all, if it is required) grid columns without refreshing the entire grid. The main idea is to create a custom DataItem template for the required columns and then update its data on the client side. The server-side values can be obtained without the grid callback by using WebMethods

See Implementation Details for more information. 

See also:
How to display dynamic data within the ASPxGridView (Live Data) without full grid updating using the ASPxCallback control

Description

To implement this task, add a custom DataItem template with ASPxLabel (or another control corresponding to the column type) for the column that should be updated:

<dx:GridViewDataSpinEditColumn FieldName="C2" Caption="Numeric (Live)"> <DataItemTemplate> <dx:ASPxLabel ID="labelC1" runat="server" Text='<%# Eval("C2") %>' OnInit="labelC1_Init"></dx:ASPxLabel> </DataItemTemplate> </dx:GridViewDataSpinEditColumn>

 Then, specify the label's ClientInstanceName property based on the row key:

protected void labelC1_Init(object sender, EventArgs e) { ASPxLabel label = sender as ASPxLabel; GridViewDataItemTemplateContainer container = label.NamingContainer as GridViewDataItemTemplateContainer; label.ClientInstanceName = "labelC1_" + container.KeyValue; }

 Please refer to the The general technique of using the Init/Load event handler KB article for more information about this technique. 


After that, call the server-side request to get updated values and pass them to the client side, for example, in the json format:

PageMethods.GetUpdatedDataFromServer(keys, onSucess, onError);

 

[WebMethod] public static string GetUpdatedDataFromServer(int[] keys) { ... List<GridDataItem> GridData = GetDataSource(); List<GridDataItem> newDataRequiredForClient = new List<GridDataItem>();
foreach (int keyValue in keys) {
	GridDataItem item = GridData.Find(x =&gt; x.ID == keyValue);
	newDataRequiredForClient.Add(item);
}
var jsonSerialiser = new JavaScriptSerializer();
var json = jsonSerialiser.Serialize(newDataRequiredForClient);
return json;

}

 Finally, update that data on the client side or generate the error (in case of any exception):

function onSucess(result) { var items = JSON.parse(result); for (var i = 0; i < items.length; i++) { var label = ASPxClientControl.GetControlCollection().GetByName("labelC1_" + items[i].ID); label.SetText(items[i].C2); ... } }

function onError(result) { alert('Something wrong!'); }


About

.NET, ASP.NET Web Forms, ASPxGridView

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 53.9%
  • Classic ASP 46.1%