Files to look at:
- Default.aspx (VB: Default.aspx)
- Default.aspx.cs (VB: Default.aspx.vb)
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
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 => 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!');
}