|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionThis is an AJAX BackgroundWhen building enterprise web applications, we often need to let the user select one item from a large list of records. For instance, on an order entry form, the user must be able to select the customer from a large list of customers. For performance reasons, it would be insane to just load a SolutionThe AJAX boom made it an easy problem to solve. An
The ControlThis custom control is based on the Setting UpTo use this Using the CodeThe first thing you need to do is to add the control to your page. This can be done through drag and drop or by writing the tags directly into the ASPX source file. Since I didn't add any relevant design-time support, I think you'd better stick with the ASPX source code. In this example we are using the <Anthem:AutoSuggestBox runat="server"
ID="asbFavoriteBand" DataKeyField="ID"
TextBoxDisplayField="Name" AutoCallBack="true"
ItemNotFoundMessage="Item not found!" >
<itemtemplate>
<%# ((Band)Container.DataItem).Name %>
</ItemTemplate>
</Anthem:AutoSuggestBox>
I think most of the property names are self-explanatory. I encourage you to go through the properties and play with them. For those unfamiliar with the Anthem.NET library, the After adding the control to the page, you should set up the event handlers. The most important event you should handle is the protected override void OnInit(EventArgs e)
{
base.OnInit(e);
this.asbFavoriteBand.TextChanged +=
new Anthem.AutoSuggestBox.TextChangedEventHandler(
asbFavoriteBand_TextChanged);
this.asbFavoriteBand.SelectedValueChanged +=
new Anthem.AutoSuggestBox.SelectedValueChangedHandler(
asbFavoriteBand_SelectedValueChanged);
}
Here's the code to handle the void asbFavoriteBand_TextChanged(object source,
Anthem.AutoSuggestEventArgs e)
{
//Creates a dataview from a datatable
DataView dv = new DataView(_dtBands);
//Filters the datatable based on the CurrentText property
dv.RowFilter = string.Format("BandName LIKE '%{0}%'", e.CurrentText);
//Sets the dataview as the control's datasource
asbFavoriteBand.DataSource = dv;
asbFavoriteBand.DataBind();
}
In the snippet above, you can use any data source on the Points of InterestThere are, definitely, some nice aspects of this control that demand a closer look at how .NET controls work, like using embedded web resources (images, JavaScript and CSS files), supporting template based content, triggering events and handling the JavaScript integration. Object-Oriented JavaScript is also worth a look. It really makes things easier.
|
||||||||||||||||||||||