Hello,
Try the following code snippet.
ASPX:
C#:
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(!Page.IsPostBack)
{
LoadCmbo1();
}
else
{
LoadCmbo2(combo1.SelectedValue);
}
}
protected
void
LoadCmbo1()
{
SqlConnection connection =
new
SqlConnection(
ConfigurationManager.ConnectionStrings[
"NorthwindConnectionString"
].ConnectionString);
SqlDataAdapter adapter =
new
SqlDataAdapter(
"SELECT * FROM Customers"
, connection);
DataTable dt =
new
DataTable();
adapter.Fill(dt);
combo1.DataTextField =
"CustomerID"
;
combo1.DataValueField =
"CustomerID"
;
combo1.DataSource = dt;
combo1.DataBind();
combo1.Items.Insert(0,
new
RadComboBoxItem(
"- Select -"
));
}
protected
void
LoadCmbo2(
string
CustomerID)
{
SqlConnection connection =
new
SqlConnection(
ConfigurationManager.ConnectionStrings[
"NorthwindConnectionString"
].ConnectionString);
SqlDataAdapter adapter =
new
SqlDataAdapter(
"SELECT * FROM Orders WHERE CustomerID=@CustomerID"
, connection);
adapter.SelectCommand.Parameters.AddWithValue(
"@CustomerID"
, CustomerID);
DataTable dt =
new
DataTable();
adapter.Fill(dt);
combo2.DataTextField =
"OrderID"
;
combo2.DataValueField =
"OrderID"
;
combo2.DataSource = dt;
combo2.DataBind();
}
protected
void
combo1_ItemsRequested(
object
sender, RadComboBoxItemsRequestedEventArgs e)
{
LoadCmbo1();
}
protected
void
combo2_ItemsRequested(
object
sender, RadComboBoxItemsRequestedEventArgs e)
{
LoadCmbo2(e.Text);
}
JS:
Thanks,
Princy.