You can create WebCombo programmatically from server-side.
In this topic, you will learn how to create WebCombo at runtime.
To create WebCombo at runtime
- Create a DIV container like following.
<div runat="server" id="DivContainer">
- Switch to View Code. At first, you need to add the following namespace.
using ISNet.WebUI.WebCombo;
- Put the following code in Page_Load.
protected void Page_Load(object sender, EventArgs e)
{
AccessDataSource access;
access = new AccessDataSource(Server.MapPath("./App_Data/Northwind.mdb"), "Select * from Customers");
access.ID = "AccessDataSource1";
WebCombo combo = new WebCombo("WebCombo1");
combo.Width = Unit.Pixel(200);
combo.Height = Unit.Pixel(20);
combo.UseDefaultStyle = true;
// Setup Events
combo.InitializeDataSource += new DataSourceEventHandler(combo_InitializeDataSource);
combo.InitializeLayout += new LayoutEventHandler(combo_InitializeLayout);
//this.Controls.Add(combo);
this.DivContainer.Controls.Add(access);
this.DivContainer.Controls.Add(combo);
}
|
- Put the following code in InitializeDataSource server-side event
to setup the DataSource.
protected void combo_InitializeDataSource(object sender, DataSourceEventArgs e)
{
// Setup DataSource
WebCombo combo = (WebCombo)sender;
combo.DataSourceID = "AccessDataSource1";
}
|
- Finally, put the following code in InitializeLayout server-side event to setup WebCombo's
behavior.
protected void combo_InitializeLayout(object sender, LayoutEventArgs e)
{
// Setup Behavior
WebCombo combo = (WebCombo)sender;
combo.DataTextField = "ContactName";
combo.DataValueField = "CustomerID";
}
|
- Run the project.