This is a migrated thread and some comments may be shown as answers.

RadGrid with ClientDS / WebServiceDataSource not working

0 Answers 53 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Manuel
Top achievements
Rank 1
Manuel asked on 25 Apr 2018, 08:20 AM

I'm trying to create a RadGrid with ClientDatasource connected to a Webservice to get, update and delete data. I created everything like the example. Unfortunately the behaviour is very strange / inconsistent. The "Get" Mathot works fine. The "Add" method on the other hand seems to work only once or sometimes twice before reloading the page completely. The "Delete" and and "Edit" Method seem not to get triggered at all.

Its cannot be a problem of the Webservice since I can manually ( over http ) trigger all of the methods without a problem. Furthermore it seems that all the parameters passed to the WS get lost. Can anyone give me an advice on what I am doing wrong here?

Here is my code:

JS:

    <script type="text/javascript">
    //<![CDATA[
    function ParameterMap(sender, args) {
 
        if (args.get_type() != "read" ) {
            args.set_parameterFormat("{ 'parameterName': 'test' }");
        }
    }
 
    function UserAction(sender, args) {
        if (sender.get_batchEditingManager().hasChanges(sender.get_masterTableView()) &&
            !confirm("Any changes will be cleared. Are you sure you want to perform this action?")) {
            args.set_cancel(true);
        }
    }
    //]]>
</script>

 

ASPX:

<telerik:RadGrid runat="server" ID="RadGrid1" ClientDataSourceID="RadClientDataSource1"
      ResolvedRenderMode="Classic" AllowFilteringByColumn="true"
      FilterType="HeaderContext"
      EnableHeaderContextMenu="true"
      EnableHeaderContextFilterMenu="true"
      PagerStyle-AlwaysVisible="true"
      AllowSorting="true" AllowPaging="True" CellSpacing="-1" GridLines="Both">
      <MasterTableView DataKeyNames="associationid" EditMode="Batch" CommandItemDisplay="Top" BatchEditingSettings-HighlightDeletedRows="true">
          <Columns>
              <telerik:GridBoundColumn DataField="associationid" HeaderText="associationid" UniqueName="column">
              </telerik:GridBoundColumn>
              <telerik:GridBoundColumn DataField="objectida" HeaderText="objectida" UniqueName="column1">
              </telerik:GridBoundColumn>
              <telerik:GridBoundColumn DataField="objectidb" HeaderText="objectidb" UniqueName="column2">
              </telerik:GridBoundColumn>
              <telerik:GridBoundColumn DataField="objectnamea" HeaderText="objectnamea" UniqueName="column3">
              </telerik:GridBoundColumn>
              <telerik:GridBoundColumn DataField="objectnameb" HeaderText="objectnameb" UniqueName="column4">
              </telerik:GridBoundColumn>
              <telerik:GridClientDeleteColumn HeaderText="Delete">
                  <HeaderStyle Width="70px" />
              </telerik:GridClientDeleteColumn>
          </Columns>
      </MasterTableView>
      <ClientSettings>
          <ClientEvents OnUserAction="UserAction" />
      </ClientSettings>
       
  </telerik:RadGrid>
 
      <telerik:RadClientDataSource ID="RadClientDataSource1" runat="server" AllowBatchOperations="True" >
      <ClientEvents OnCustomParameter="ParameterMap"  />
      <DataSource >
          <WebServiceDataSourceSettings BaseUrl="http://localhost/DataService/DataService.svc/" ServiceType="Default">
              <Select Url="GetAssocs" DataType="JSON" />
              <Update Url="UpdateAssoc" DataType="JSON" />
              <Insert Url="AddAssoc" DataType="JSON" />
              <Delete Url="DeleteAssoc" DataType="JSON" />
          </WebServiceDataSourceSettings>
      </DataSource>
 
      <Schema>
          <Model ID="associationid">
              <telerik:ClientDataSourceModelField FieldName="associationid" DataType="String" />
              <telerik:ClientDataSourceModelField FieldName="objectida" DataType="String" />
              <telerik:ClientDataSourceModelField FieldName="objectidb" DataType="String" />
              <telerik:ClientDataSourceModelField FieldName="objectnamea" DataType="String" />
              <telerik:ClientDataSourceModelField FieldName="objectnameb" DataType="String" />
          </Model>
      </Schema>
 
  </telerik:RadClientDataSource>

 

Webservice:

[ServiceKnownType(typeof(Association))]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class DataService : IDataService
{
    [WebGet]
    public List<Association> GetAssocs()
    {
        using (EventLog eventLog = new EventLog("Application"))
        {
            eventLog.Source = "Application";
            eventLog.WriteEntry("Log message GET", EventLogEntryType.Information, 101, 1);
        }
 
        List<Association> x = new List<Association>();
 
        for (int i = 0; i < 10; i++)
        {
            Association a = new Association();
 
            a.associationid = i.ToString();
            a.objectida = i.ToString();
            a.objectidb = i.ToString();
            a.objectnamea = i.ToString();
            a.objectnameb = i.ToString();
 
            x.Add(a);
        }
 
        return x;
 
    }
    [WebGet]
    public void UpdateAssoc(string JSONstring)
    {
        try
        {
            using (EventLog eventLog = new EventLog("Application"))
            {
                eventLog.Source = "Application";
                eventLog.WriteEntry("Log " + JSONstring.ToString(), EventLogEntryType.Information, 101, 1);
            }
        }
        catch (Exception ex)
        {
 
            throw ex;
        }
 
    
    }
 
    [WebGet]
    public void AddAssoc(string JSONstring)
    {
 
        using (EventLog eventLog = new EventLog("Application"))
        {
            eventLog.Source = "Application";
            eventLog.WriteEntry("Log message ADD", EventLogEntryType.Information, 101, 1);
        }
 
    }
 
    [WebGet]
    public void DeleteAssoc(string JSONstring)
    {
 
        using (EventLog eventLog = new EventLog("Application"))
        {
            eventLog.Source = "Application";
            eventLog.WriteEntry("Log message DELETE", EventLogEntryType.Information, 101, 1);
        }
 
    }
 
}

 

and

[ServiceContract]
  public interface IDataService
  {
      [OperationContract]
      [WebGet]
      List<Association> GetAssocs();
 
      [OperationContract]
      [WebGet]
      void UpdateAssoc(string JSONstring);
 
      [OperationContract]
      [WebGet]
      void AddAssoc(string JSONstring);
 
      [OperationContract]
      [WebGet]
      void DeleteAssoc(string JSONstring);
  }
 
 
  [DataContract]
  public class Association
  {
 
      [DataMember]
      public string associationid { get; set; }
 
      [DataMember]
      public string objectida { get; set; }
 
      [DataMember]
      public string objectidb { get; set; }
 
      [DataMember]
      public string objectnamea { get; set; }
 
      [DataMember]
      public string objectnameb { get; set; }
 
 
  }

 

 

 

 

No answers yet. Maybe you can help?

Tags
Grid
Asked by
Manuel
Top achievements
Rank 1
Share this question
or