Intersoft WebCombo Documentation
How-to: Add New Item to Web Service
See Also Send comments on this topic.
Intersoft WebCombo > WebCombo Features Overview > Features Added In WebCombo 5 > Client Data Services > How-to: Add New Item to Web Service

Glossary Item Box

WebService data source type enables you to connect WebCombo to a Web Service in elegant fashion, which is done through properties configuration without requiring you to write Javascript code.

This topic shows how to add new item to Web Service.

To add new item to WebService

  1. Right-click on WebCombo control and select Properties.
  2. Expand LayoutSettings and set AllowAddItem to True.
  3. Create WebService.asmx in the same level with your aspx name.
  4. Go to App_Code and add method GetEmployees and InsertEmployee in WebService.cs.

    C# Copy Code
    [System.Web.Script.Services.ScriptService]
    [WebMethod]
    public QueryResult GetEmployees(DataSourceSelectArguments selectArguments)
    {
       NorthwindDataContext context = new NorthwindDataContext();
       context.DeferredLoadingEnabled = false;
       context.ObjectTrackingEnabled = false;
    
       WebComboDataProvider<Employee> query = new WebComboDataProvider<Employee>(context.Employees);
       return query.Select(selectArguments);
    }
    
    [WebMethod]public TransactionResult InsertEmployee(Employee newObject)
    {
       NorthwindDataContext context = new NorthwindDataContext();
       WebComboDataProvider<Employee> query = new WebComboDataProvider<Employee>(context.Employees);
       TransactionResult result = new TransactionResult();
    
       // only add new item when the submitted firstname has not existed in our database
       if (context.Employees.Where(e => e.FirstName == newObject.FirstName).Count() == 0)
       {
          result = query.Insert(newObject);
          result.NewID = newObject.EmployeeID;      result.AffectedResults = 1;   }
    
          return result;
    }

  5. Set the properties based on the table and code below.

    Property Value
    BindingOperationMode ClientBinding
    DataSourceType WebService
    ServiceUrl WebCombo_WebService.asmx (or any .asmx created by user)
    ItemTypeName Employee
    SelectMethod GetEmployees
    InsertMethod InsertEmployee

    HTML Copy Code
    <ISWebCombo:WebCombo ID="WebCombo1" runat="server" DataTextField="FirstName" DataValueField="EmployeeID"
       Height="20px" UseDefaultStyle="True" Width="200px" BindingOperationMode="ClientBinding">
       <LayoutSettings AllowAddItem="True">   
       </LayoutSettings>
       <ClientBindingSettings DataSourceType="WebService" ServiceUrl="WebCombo_WebService.asmx" ItemTypeName="Employee">
          <ServiceMethods SelectMethod="GetEmployees" InsertMethod="InsertEmployee" />
       </ClientBindingSettings>
    </ISWebCombo:WebCombo>

  6. Run the project.

See Also