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
- Right-click on WebCombo control and select Properties.
- Expand LayoutSettings and set AllowAddItem to True.
- Create WebService.asmx in the same level with your aspx name.
- 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; }
- 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>
- Run the project.