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
- Add two instances of WebCombo to the WebForm. Specify the Name as WebCombo1 and WebCombo2 respectively.
- Bind WebCombo1 to AccessDataSource. In this sample, you will use Suppliers and Products tables in NorthWind database.
- 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. - In WebCombo2's InitializeDataSource event, add the following code:
C# Copy 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";
- 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; }
- 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 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; }
- Run the project.
Tasks
How-to: Use combined dependencies linked WebCombo
How-to: Use multiple dependencies linked WebCombo
How-to: Use single dependencies linked WebCombo
How-to: Use unbound linked WebCombo
Concepts
{Linked WebCombo}
References
FilterDataMember Property
AllowAutoQueryHandler Property
DataTextField Property
DataValueField Property
OnAfterItemSelected Property
OnBeforeRequest Property
InitializeDataSource Event