ASPX Code
<
asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">
<table class="style11">
<tr>
<td class="style12" valign="top">
<asp:Label ID="Label3" runat="server" Font-Names="Calibri" Font-Size="Medium"
Text="Select State:"></asp:Label>
</td>
<td class="style13">
<telerik:RadComboBox ID="RadComboBox1" Runat="server" width= "186px"
OnClientSelectedIndexChanging="LoadStates"
OnItemsRequested="RadComboBox1_ItemsRequested"
Skin="Sunset" Height="19px" EnableLoadOnDemand="False">
</telerik:RadComboBox>
</td>
<td class="style14" valign="top">
<asp:Label ID="Label4" runat="server" Font-Names="Calibri" Font-Size="Medium"
Text="Select Site:"></asp:Label>
</td>
<td valign="top">
<telerik:RadComboBox ID="RadComboBox2" Runat="server"
Width="186px"
OnClientSelectedIndexChanging="LoadProperties"
OnClientItemsRequested="ItemsLoaded"
OnItemsRequested="RadComboBox2_ItemsRequested" Height="19px"
Skin="Sunset" >
</telerik:RadComboBox>
</td>
</tr>
<tr>
<td class="style12">
</td>
<td colspan="3">
</td>
</tr>
</table>
<script type="text/javascript">
//global variables for the Properties combobox
var propertiesCombo;
function pageLoad() {
// initialize the global variables
// in this event all client objects
// are already created and initialized
propertiesCombo = $find(
"<%= RadComboBox2.ClientID %>");
}
function LoadProperties(combo, eventArqs) {
var item = eventArqs.get_item();
propertiesCombo.set_text(
"Loading...");
// if a continent is selected
if (item.get_index() > 0) {
// this will fire the ItemsRequested event of the
// properties combobox passing the State as a parameter
propertiesCombo.requestItems(item.get_value(),
false);
}
else {
// the -Select a continent- item was chosen
propertiesCombo.set_text(
" ");
propertiesCombo.clearItems();
}
}
function ItemsLoaded(combo, eventArqs) {
propertiesCombo = $find(
"<%= RadComboBox2.ClientID %>");
if (combo.get_items().get_count() > 0) {
// pre-select the first item
combo.set_text(combo.get_items().getItem(0).get_text());
combo.get_items().getItem(0).highlight();
}
combo.showDropDown();
}
</script>
</asp:Content>
C# Code
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
//fill the continents combo
LoadStates();
}
}
protected void LoadStates()
{
string path = Server.MapPath("~/App_Data/xxx.mdb");
OleDbConnection dbCon = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path);
dbCon.Open();
OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT State, PropertyNumber FROM tblSiteInfo ORDER By PropertyNumber", dbCon);
DataTable dt = new DataTable();
adapter.Fill(dt);
dbCon.Close();
RadComboBox1.DataTextField =
"State";
RadComboBox1.DataValueField =
"State";
RadComboBox1.DataSource = dt;
RadComboBox1.DataBind();
//insert the first item
RadComboBox1.Items.Insert(0,
new RadComboBoxItem("- Select a state -"));
foreach (RadComboBoxItem item in RadComboBox1.Items)
{
item.ToolTip = item.Text;
}
}
protected void LoadProperties(string State)
{
string path = Server.MapPath("~/App_Data/xxx.mdb");
OleDbConnection dbCon = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path);
dbCon.Open();
//select a Property number based on the state
OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT State, PropertyNumber FROM tblSiteInfo WHERE State=@State ORDER By PropertNumber", dbCon);
adapter.SelectCommand.Parameters.AddWithValue(
"@State", State);
DataTable dt = new DataTable();
adapter.Fill(dt);
dbCon.Close();
RadComboBox2.DataTextField =
"PropertyNumber";
RadComboBox2.DataValueField =
"PropertyNumber";
RadComboBox2.DataSource = dt;
RadComboBox2.DataBind();
foreach (RadComboBoxItem item in RadComboBox2.Items)
{
item.ToolTip = item.Text;
}
}
protected void RadComboBox1_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)
{
LoadStates();
}
protected void RadComboBox2_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)
{
// e.Text is the first parameter of the requestItems method
// invoked in LoadCountries method
LoadProperties(e.Text);
}
}