This walkthrough shows you how to retrieving data using Load-on-Demand feature in ISDataSourcecontrol.
During this walkthrough, you will learn how to do the following:
- Use ISDataSource.
- Use SmartTag to set DataSource.
Prerequisites
In order to complete this walkthrough, you will need the following:
- Access to the Microsoft Access Northwind database.
- Visual Studio 2005 Application.
Step-By-Step Instructions
To create new web application and bind WebCombo to CustomObject
- Create DataSet named NorthWind.
- Create partial class CustomersTableAdapter.
C# Copy Code using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using System.Data.OleDb; namespace NorthWindTableAdapters { public partial class CustomersTableAdapter { public DataTable GetData(int maximumRows, int startRowIndex) { int topRows = startRowIndex + maximumRows; OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT TOP " + topRows + " * FROM Customers", this.Connection); NorthWind.CustomersDataTable baseData = new NorthWind.CustomersDataTable(); adapter.Fill(startRowIndex, maximumRows, new DataTable[] { baseData }); return baseData; } public DataTable GetData(int maximumRows, int startRowIndex, string queryText) { NorthWind.CustomersDataTable baseData = new NorthWind.CustomersDataTable(); if (string.IsNullOrEmpty(queryText)) queryText = string.Empty; // do not need to populate data in first load or standard postback, without value (queryText is empty) if (maximumRows == 0 && startRowIndex == 0 && string.IsNullOrEmpty(queryText)) return baseData; if (maximumRows > 0) { // retrieves a list of data based on given startRow and maxRow int topRows = startRowIndex + maximumRows; OleDbDataAdapter adapter = new OleDbDataAdapter("Select TOP " + topRows + " * FROM Customers WHERE ContactName LIKE '" + queryText + "%'", this.Connection); adapter.Fill(startRowIndex, maximumRows, new DataTable[] { baseData }); } else { // bind to single value, this will be called during first load or postback, and value is filled. // note that the query is made against value field. if(!string.IsNullOrEmpty(queryText)) { OleDbDataAdapter adapter = new OleDbDataAdapter("Select * from Customers Where CustomerID = '" + queryText + "'", this.Connection); adapter.Fill(baseData); } } return baseData; } public int SelectCount(string queryText) { OleDbDataAdapter myDa = new OleDbDataAdapter(); string selectCommand = "Select Count(*) From customers Where contactName like '" + queryText + "%'"; myDa.SelectCommand = new OleDbCommand(selectCommand, this.Connection); this.Connection.Open(); int result = (int)myDa.SelectCommand.ExecuteScalar(); this.Connection.Close(); return result; } } }
- Drag ISDataSource instance from ToolBar to WebForm.
- Bind the DataSet to ISDataSource.
- Open ISDataSource.NET Designer.
- Set EnablePaging = Yes
SelectCountMethod = "SelectCount"
MaxiumRowsParameterName ="maximumRows"
StartRowIndexParameterName ="startRowIndex"
- Drag WebCombo instance from ToolBar to WebForm.
- Click the SmartTag on the upper right of the WebCombo.
- Set DataSource to ISDataSource
- Set the DataTextField and DataValueField for WebCombo.
For more information, please refer to WebCombo.NET V4.0 Sample - LoadOnDemand.aspx