Intersoft WebCombo Documentation
How-to: Implement linked WebCombo functionality using column that is not DataTextField or DataValueField as the FilterDataMember
See Also Send comments on this topic.
Intersoft WebCombo > WebCombo Advanced Features > Advanced How-to Topics > How-to: Implement linked WebCombo functionality using column that is not DataTextField or DataValueField as the FilterDataMember

Glossary Item Box

Using built-in LinkedWebCombo feature, the WebCombo should be populated with the data during initialization.

In this topic, you will learn how to implement linked WebCombo functionality using column that is not DataTextField or DataValueField as the FilterDataMember.

To implement linked WebCombo functionality

  1. Add two instances of WebCombo to the WebForm. Specify the Name as WebCombo1 and WebCombo2 respectively.
  2. Bind WebCombo1 to AccessDataSource. In this sample, you will use Suppliers and Products tables in NorthWind database.
  3. Set AllowAutoQueryHandler property of WebCombo2 to False. AllowAutoDataCaching property will automatically set to False. By setting AllowAutoQueryHandler property to false, you do not need to use the built in query function and thus, developing our own Requery method.

    WebCombo2_InitializeDataSource event will be triggered in every request.
  4. In WebCombo2's InitializeDataSource event, add the following code:

    C# Copy ImageCopy Code
    string queryText = "";
    DataTable dt = new DataTable("Products");                       
    
    if(WebCombo1.Value != "" && WebCombo1.Value != null)
    {
       queryText = "SupplierID = " + WebCombo1.Value;
       OleDbDataAdapter da = new OleDbDataAdapter("Select * From Products 
            Where " + queryText,oleDbConnection1);
       da.FillSchema(dt,SchemaType.Mapped);
       da.Fill(dt);
       e.DataSource = dt;                      
    }
    
    WebCombo2.DataMember = "Products";
    WebCombo2.DataTextField = "ProductName";
    WebCombo2.DataValueField = "ProductID";
    

  5. A request is already made when you select a value from WebCombo1. Therefore, you need to define some codes to force a request when you want to load data in WebCombo2.  You can put the following code in WebCombo1's OnAfterItemSelected client side events:

    Javascript Copy Code
    function WebCombo1_OnAfterItemSelected(controlId)
    {
       var WebCombo2 = ISGetObject("WebCombo2");
       
       //clears the data list in WebCombo2
       WebCombo2.NeedClearList = true;
       WebCombo2.IsDirty = true; 
       
       return true;
    }                     
    

  6. User cannot select a value in WebCombo2 before a value is selected in WebCombo1. Hence, you need to define a validation function. Specify a function for WebCombo2's OnBeforeRequest client side events, and add the following code:

    JavaScript Copy ImageCopy Code
    function WebCombo2_OnBeforeRequest(controlId, action)
    {
       var WebCombo1 = ISGetObject("WebCombo1");
       if(action == "LoadData")
       {
          if(WebCombo1.Value == "" || WebCombo1.Value == null)
          {
             alert("Please select a value for the following webcombo 
             input : " + WebCombo1.Name);
             return false;
          }
       }
          return true;
    }
    

  7. Run the project.

See Also