Hi Diego,
Thanks for using Syncfusion products.
We have tried a sample with changing XML file and also XML data alone. While changing xml file or data, we need to call the DataBind() method for reflecting the changes.
Refer to the attached sample with the above scenario,
http://www.syncfusion.com/downloads/support/directtrac/general/ze/WebApplication211739835964.zip
In the sample, we have changed the xml data of the “Dashboard_1.xml” file in server side click event of the button as follows,
<ej:grid runat="server" id="dgDashboard1" DataSourceId="XmlDataSource1" AllowSelection="False" EnableRowHover="False" ShowSummary="True" AllowGrouping="True"> . . . . </ej:grid>
protected void Button1_Click(object sender, EventArgs e) { XmlDocument doc = new XmlDocument(); doc.Load(Server.MapPath("~/App_Data/Dashboard_1.xml")); XmlNode node; node = doc.DocumentElement; foreach (XmlNode node1 in node.ChildNodes) { foreach (XmlNode node2 in node1.ChildNodes) { if (node2.Name == "Competidores") { int price = int.Parse(node2.InnerText); int newprice = price + 20; node2.InnerText = newprice.ToString(); } } } doc.Save(Server.MapPath("~/App_Data/Dashboard_1.xml")); dgDashboard1.DataBind(); } |
We can achieve your requirement using “PageMethods” concept in which we can access the server side method from client side. In the above sample, we have read the xml file in “GetPageMethod” and returned the data to client side. We access that data using “onSuccess” method in client side. We have updated the returned data to the Grid using “dataSource” method of Grid. <ej:grid runat="server" id="dgDashboard1" DataSourceId="XmlDataSource1" </ej:grid> <asp:ScriptManager runat="server" EnablePageMethods="true"> function refresh() { debugger; var newDate = new Date(); $('#<%= Label1.ClientID %>').text(newDate.toString()); PageMethods.GetPageMethod(onSucceed, onError); } function onSucceed(result) { //Instance of the grid var gridObj = $('#<%= dgDashboard1.ClientID %>').data("ejGrid"); //Assigning datasource to the grid gridObj.dataSource(result); } function onError() { } [System.Web.Services.WebMethod] public static IEnumerable GetPageMethod() { DataSet ds = new DataSet(); FileStream fs = new FileStream(HostingEnvironment.MapPath("~/App_Data/Dashboard_1.xml"), FileMode.Open, FileAccess.Read); StreamReader reader = new StreamReader(fs); ds.ReadXml(reader); fs.Close(); //Converting datatable data to Json data IEnumerable data = Syncfusion.JavaScript.Utils.DataTableToJson(ds.Tables[0]); return data;
AllowSelection="False" EnableRowHover="False">
. . . .
. . . .
</asp:ScriptManager>
<script type="text/javascript">
. . . .
. . . .
</script>
Default.aspx.cs
}
We have attached the sample below for your reference,
http://www.syncfusion.com/downloads/support/directtrac/general/SY73BB~1-85021835.ZIP
Regards,
Gowthami V.
Hi Diego,
We can achieve your requirement using “PageMethods” concept in which we can access the server side method from client side.
In the above sample, we have read the xml file in “GetPageMethod” and returned the data to client side. We access that data using “onSuccess” method in client side. We have updated the returned data to the Grid using “dataSource” method of Grid.
<ej:grid runat="server" id="dgDashboard1" DataSourceId="XmlDataSource1"
AllowSelection="False" EnableRowHover="False">
. . . .
. . . .
</ej:grid>
<asp:ScriptManager runat="server" EnablePageMethods="true">
</asp:ScriptManager>
<script type="text/javascript">
. . . .
. . . .
function refresh() {
debugger;
var newDate = new Date();
$('#<%= Label1.ClientID %>').text(newDate.toString());
PageMethods.GetPageMethod(onSucceed, onError);
}
function onSucceed(result) {
//Instance of the grid
var gridObj = $('#<%= dgDashboard1.ClientID %>').data("ejGrid");
//Assigning datasource to the grid
gridObj.dataSource(result);
}
function onError()
{ }
</script>
Default.aspx.cs
[System.Web.Services.WebMethod]
public static IEnumerable GetPageMethod()
{
DataSet ds = new DataSet();
FileStream fs = new FileStream(HostingEnvironment.MapPath("~/App_Data/Dashboard_1.xml"), FileMode.Open, FileAccess.Read);
StreamReader reader = new StreamReader(fs);
ds.ReadXml(reader);
fs.Close();
//Converting datatable data to Json data
IEnumerable data = Syncfusion.JavaScript.Utils.DataTableToJson(ds.Tables[0]);
return data;
}
We have attached the sample below for your reference,
http://www.syncfusion.com/downloads/support/directtrac/general/SY73BB~1-85021835.ZIP
Regards,
Gowthami V.