Intersoft WebCombo Documentation
Walkthrough: Implementing requery method using traditional DataSource
See Also Send comments on this topic.
Intersoft WebCombo > WebCombo Features Overview > Data Binding Wakthroughs > Walkthrough: Implementing requery method using traditional DataSource

Glossary Item Box

This walkthrough shows you how to implement requery method using traditional DataSource.

During this walkthrough, you will learn how to do the following:

 Prerequisites

In order to complete this walkthrough, you will need the following:

  • Access to the Microsoft Access Northwind database.
  • Visual Studio 2005/208/2010 Application.

 Step-By-Step Instructions

To create new web application and bind WebCombo with DataSource

  1. Launch Visual Studio.NET 2005.
  2. Click on File menu, then select New and click Web Site.
  3. Select ASP.NET Web Site in the Template box and set Location to HTTP.
  4. Named the Web Site and click OK.
  5. Right-click on Project's name and select Add New Item.
  6. Select Intersoft AppForm in the My Templates box and named it as Walkthrough.aspx.
  7. Drag WebCombo instance from ToolBar to WebForm.
  8. Double click on WebCombo instance and write the following code:

    C# Copy Code
    protected void WebCombo1_InitializeDataSource(object sender, ISNet.WebUI.WebCombo.DataSourceEventArgs e)
    {
        OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\NorthWind.mdb");
        OleDbDataAdapter da = new OleDbDataAdapter();
        DataSet ds = new DataSet();
        string queryText = "";
    
        da.SelectCommand = new OleDbCommand();
        da.SelectCommand.Connection = conn;
    
        if (!e.IsFlyDataRequest)
        {
           if (WebCombo1.Value != "" && WebCombo1.Value != null)
           {
             da.SelectCommand.CommandText = "Select * From Customers Where " + WebCombo1.DataValueField + " = '" + WebCombo1.Value + "'";
             da.Fill(ds);
             e.DataSource = ds;
           }
         }
         else
         {
           int TopRows = e.StartRow + e.RowCount;
           queryText = WebCombo1.DataTextField + " Like '" + e.QueryText + "%'";
    
           da.SelectCommand.CommandText = "Select TOP " + TopRows + " * From Customers Where " + queryText;
    
           da.Fill(ds, e.StartRow, e.RowCount, "Table1");
                
           if (ds.Tables[0].Rows.Count < 3)
           {            
              queryText += " Or " + WebCombo1.DataTextField + " Like '" + e.QueryText.Substring(0, 1) + "%'";
              da.SelectCommand.Commandtext = "Select TOP " + TopRows + " * From Customers Where " + queryText;
            
              ds.Tables[0].Rows.Clear();
              da.Fill(ds, e.StartRow, e.RowCount, "Table1");
            }
            e.DataSource = ds;
    
            WebCombo1.SkipRowParsing = true;
                
            conn.Open();
            OleDbCommand cmd = new OleDbCommand();
            cmd.Commandtext = "Select Count(CustomerID) From Customers Where " + queryText;
            cmd.Connection = conn;
    
            WebCombo1.TotalDataSourcerows = int.Parse(cmd.ExecuteScalar().ToString());
          }     
    }
    

  9. On Page_Load event handler, put the following code:

    C# Copy Code
    WebCombo1.AllowAutoQueryHandler = false;
    WebCombo1.DataTextField = "ContactName";
    WebCombo1.DataValueField = "CustomerID";
    

  10. Run the project and the combo will look like following.

See Also