I'm having issues with dependent drop down menus. I have 2 dropdowns, Category and SubCategory. In a straight ASP.NET control page I have it working perfectly with OnSelectedIndexChanged.
With the telerik version though I have to assume something to do with xhtml output (the produced code is an <li> instead of an< option>)or xhtml page (the example on the website has simply Xhtmlpage instead of System.Web.UI.Page) or even the change from selected index to select value (as in LoadSubCategories(e.Value.ToString())) is causing the the first dropdown menu to not load. As you might expect, the second menu can not load unless the first loads.
Here's is the code...any help would be appreciated. Thanks!
With the telerik version though I have to assume something to do with xhtml output (the produced code is an <li> instead of an< option>)or xhtml page (the example on the website has simply Xhtmlpage instead of System.Web.UI.Page) or even the change from selected index to select value (as in LoadSubCategories(e.Value.ToString())) is causing the the first dropdown menu to not load. As you might expect, the second menu can not load unless the first loads.
Here's is the code...any help would be appreciated. Thanks!
ASPX PAGE | |
... | |
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> | |
... | |
<telerik:RadScriptManager ID="RadScriptManager1" runat="server" /> | |
<telerik:RadComboBox ID="Categories" runat="server" | |
OnClientSelectedIndexChanged="Categories_SelectedIndexChanged" | |
OnItemsRequested="RadComboBox1_ItemsRequested" /> | |
<telerik:RadComboBox ID="SubCategories" runat="server" | |
OnItemsRequested="RadComboBox2_ItemsRequested" /> | |
C# CODE-BEHIND | |
using System; | |
using System.Data; | |
using System.Data.SqlClient; | |
using System.Configuration; | |
using System.Web; | |
using System.Web.Security; | |
using Telerik.Web.UI; | |
public partial class tests_Default : System.Web.UI.Page | |
{ | |
protected void Page_Load(object sender, EventArgs e) | |
{ | |
// pre-populate Categories | |
if (!Page.IsPostBack) | |
{ | |
LoadCategories(); | |
} | |
} | |
protected void LoadCategories() | |
{ | |
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); | |
conn.Open(); | |
SqlDataAdapter adapter = new SqlDataAdapter("SELECT id, category_name, sort_order FROM Categories", conn); | |
DataTable dt = new DataTable(); | |
adapter.Fill(dt); | |
conn.Close(); | |
Categories.DataTextField = "category_name"; | |
Categories.DataValueField = "id"; | |
Categories.DataSource = dt; | |
// if datatable is null | |
// do not bind dropdown | |
if(dt.Rows.Count != 0) { | |
Categories.DataBind(); | |
} | |
} | |
protected void LoadSubCategories(string categoryID) | |
{ | |
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); | |
conn.Open(); | |
SqlDataAdapter adapter = new SqlDataAdapter("SELECT id AS subcategoryID, subcategory_name FROM SubCategories WHERE category_id =" + categoryID, conn); | |
DataTable dt = new DataTable(); | |
adapter.Fill(dt); | |
conn.Close(); | |
SubCategories.DataTextField = "subcategory_name"; | |
SubCategories.DataValueField = "subcategoryID"; | |
SubCategories.DataSource = dt; | |
SubCategories.DataBind(); | |
} | |
protected void Categories_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e) | |
{ | |
//Response.Write("e.Text = " + e.Text + "<br>e.Value = " + e.Value); | |
LoadSubCategories(e.Value.ToString()); | |
} | |
protected void RadComboBox1_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e) | |
{ | |
LoadCategories(); | |
} | |
protected void RadComboBox2_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e) | |
{ | |
Response.Write("e.Text = " + e.Text + "<br>e.Value = " + e.Value); | |
LoadSubCategories(e.Value.ToString()); | |
} | |
} | |