<ej:Button ID="open" runat="server" Text="open" ClientSideOnClick="openDialog" Type="Button"></ej:Button>
|
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always">
<ContentTemplate>
<div style="padding-top:20px">
<ej:Button ID="open" runat="server" Text="open" ClientSideOnClick="openDialog"></ej:Button>
------------------------------
<ej:Grid ID="Grid" runat="server" AllowTextWrap="true" AllowSorting="true" OnServerExcelExporting="Grid_ServerExcelExporting" AllowPaging="true">
<Columns>
-----------------------------------------
</Columns>
<ClientSideEvents ActionComplete="complete" />
---------------------------------------
function complete(args) {
if (args.requestType == "refresh") {
PageMethods.GetRefresh();
}
}
-----------------------------------------
[System.Web.Services.WebMethod]
public static string GetRefresh()
{
-----
} |
var grid = $("#Grid").ejGrid("instance");
grid.dataSource(response);
|
<ej:Grid ID="Grid1" runat='server' AllowPaging="true">
<DataManager URL="Default.aspx/DataSource" UpdateURL="/Default.aspx/PerformUpdate" InsertURL="Default.aspx/PerformInsert" RemoveURL="Default.aspx/PerformDelete" Adaptor="WebMethodAdaptor" />
<EditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" />
<ToolbarSettings ShowToolbar="true" ToolbarItems="add,edit,delete,update,cancel" />
<Columns>
<ej:Column Field="OrderID" IsPrimaryKey="true" Width="80" />
<ej:Column Field="CustomerID" Width="100" />
<ej:Column Field="EmployeeID" Width="80" />
<ej:Column Field="Freight" Format="{0:C2}" Width="80" />
</Columns>
</ej:Grid>
<WebMethod> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
Public Shared Function DataSource(value As Syncfusion.JavaScript.DataManager) As Object
Dim Data As IEnumerable = New NorthWNDDataContext().OrderTables.ToList()
Dim count As Integer = Data.AsQueryable().Count()
Dim operation As New Syncfusion.JavaScript.DataSources.DataOperations()
Data = operation.Execute(Data, value)
Return New With { _
Key .result = Data, _
Key .count = count _
}
End Function
<WebMethod> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
Public Shared Sub PerformInsert(value As OrderTable)
. . ..
db.SubmitChanges()
End Sub
<WebMethod> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
Public Shared Sub PerformUpdate(value As OrderTable)
. . .
db.SubmitChanges()
End Sub
<WebMethod> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
Public Shared Sub PerformDelete(key As Integer)
.. .
db.SubmitChanges()
End Sub |
<ej:Button ID="open" runat="server" Text="open" ClientSideOnClick="openDialog" Type="Button"></ej:Button>
<ej:Grid ID="Grid" runat='server' AllowPaging="true">
<DataManager URL="Default.aspx/DataSource" UpdateURL="/Default.aspx/PerformUpdate" InsertURL="Default.aspx/PerformInsert" RemoveURL="Default.aspx/PerformDelete" Adaptor="WebMethodAdaptor" />
. . . . .
</ej:Grid>
<div id="dlg" style="visibility: hidden" class="control">
<ej:Dialog ID="dialog" Title="Unos" ShowOnInit="false" runat="server" ShowRoundedCorner="true">
<DialogContent>
<ej:Button Text="Save" runat="server" ClientSideOnClick="Save" ID="saveButton" Size="Small" ShowRoundedCorner="true" ContentType="TextAndImage" PrefixIcon="e-save" />
</DialogContent>
</ej:Dialog>
</div>
<script>
function Save() {
var obj = $("#MainContent_Grid").ejGrid("instance");
//Manually update the Grid data
var data = { OrderID: Math.ceil(Math.random() * 1000), CustomerID: "VINET" + Math.ceil(Math.random() * 10) };
obj.addRecord(data);//Grid method
$(".dlg").hide();
$("#MainContent_dialog").ejDialog("close");
}
function openDialog() {
$(".dlg").show()
$("#MainContent_dialog").ejDialog("open");
}
</script> |
Thank you.
I would like to use CRUD methods with WebMethodAdaptor.
I have put the DataManager URL to call the DataSource function just like in your example
<DataManager URL="Default.aspx/DataSource" Adaptor="WebMethodAdaptor" />
I am getting the data from a stored procedure to datatable and converting it with .AsEnumerable()
Public Shared Function DataSource(value As Syncfusion.JavaScript.DataManager) As Object
Dim db As New Db
Dim Data As IEnumerable = db.getData("GH_HUO_Uninsured_Vehicles_Select").AsEnumerable()
Dim count As Integer = Data.AsQueryable().Count()
Dim operation As New Syncfusion.JavaScript.DataSources.DataOperations()
Data = operation.Execute(Data, value)
Return New With {
Key .result = Data,
Key .count = count
}
End Function
On debug i can see that the data is populated correctly with both .count and .data but the grid just shows the loading icon spinning indefinitely and does not populate.
See the attached pic please.
If we misunderstood your query, please provide the following information to analyze the issue.1) In the code example, you have sent the ajax post to insert a record. How you are getting the inserted record in the button click?2) Explain the scenario to insert the record into the Grid?
1) I don't understand the sentence: How you are getting the inserted record in the button click?
It's all in my previous posts :-) Through a Save function
2) When populating the controls from the Dialog the Save button executes AJAX calling Save method which inserts a record to DB
After that the grid needs to be refreshed, but i am willing to use CRUD if you could help me solve this.
Public Sub ExecuteStoredProcedure(command As SqlCommand)
Dim connection As New SqlConnection(conn)
connection.Open()
command.Connection = connection
command.CommandType = CommandType.StoredProcedure
command.ExecuteNonQuery()
connection.Close()
End Sub