Returning different values in a combobox

Posted by Jopito under ASP.NET on 11/7/2013 | Points: 10 | Views : 1023 | Status : [Member] | Replies : 7
Hellow friends,i have two comboboxes in my form.One contains items Consumer and Biller,
The other combobox contains Individual,business, company.How can i customize it such that when one selects Biller from the first combobox then the second combobox items will show only business and Company but not the three Items.

Thank you

Mark as answer if satisfied


Responses

Posted by: Allemahesh on: 11/7/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
You can see the below code for this:-

<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Text="-- Select --" Value="-- Select --"></asp:ListItem>
<asp:ListItem Text="Consumer" Value="Consumer"></asp:ListItem>
<asp:ListItem Text="Biller" Value="Biller"></asp:ListItem>
</asp:DropDownList>
<br />
<br />
<asp:DropDownList ID="DropDownList2" runat="server">
<asp:ListItem Text="-- Select --" Value="-- Select --"></asp:ListItem>
<asp:ListItem Text="Individual" Value="Individual"></asp:ListItem>
<asp:ListItem Text="Business" Value="Business"></asp:ListItem>
<asp:ListItem Text="Company" Value="Company"></asp:ListItem>
</asp:DropDownList>
</div>
</form>



protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList1.SelectedIndex > 0)
{
DropDownList2.Items.Clear();
if (DropDownList1.SelectedValue.ToString().ToLower() == "biller")
{
DropDownList2.Items.Add(new ListItem("Business", "Business"));
DropDownList2.Items.Add(new ListItem("Company", "Company"));
}
else
{
DropDownList2.Items.Add(new ListItem("Individual", "Individual"));
DropDownList2.Items.Add(new ListItem("Business", "Business"));
DropDownList2.Items.Add(new ListItem("Company", "Company"));
}
DropDownList2.Items.Insert(0, new ListItem("-- Select --", "-- Select --"));
}
}


I have tested this and working fine. Please let me know if you have other issue.

Happy Coding,
If it helps you or directs U towards the solution, MARK IT AS ANSWER

Jopito, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 11/7/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Refer
http://stackoverflow.com/questions/3469287/populate-one-combobox-based-on-selection-of-another
http://stackoverflow.com/questions/11225286/bind-combo-box-based-on-another-combo-boxs-selected-item-mvvm-wpf

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Jopito, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jopito on: 11/7/2013 [Member] Starter | Points: 25

Up
0
Down

Am getting this kind of errors

Error 7 Argument 1: cannot convert from 'System.Web.UI.WebControls.ListItem' to 'Telerik.Web.UI.RadComboBoxItem'


Mark as answer if satisfied

Jopito, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 11/7/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Refer
http://demos.telerik.com/aspnet-ajax/combobox/examples/functionality/multiplecomboboxes/defaultcs.aspx
http://stackoverflow.com/questions/6261075/how-to-bind-the-radcombobox-at-runtime-in-asp-net

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Jopito, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jopito on: 11/7/2013 [Member] Starter | Points: 25

Up
0
Down
Am now getting this error
'Telerik.Web.UI.RadComboBoxItem' is a 'type', which is not valid in the given context,

UserTypeRadcombobox.Items.Add(Telerik.Web.UI.RadComboBoxItem("Business", "Business"));
UserTypeRadcombobox.Items.Add(Telerik.Web.UI.RadComboBoxItem("Company", "Company"));



Mark as answer if satisfied

Jopito, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 11/7/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Hi,
The following link will give you an idea to add Items to RabComboBox
http://demos.telerik.com/aspnet-ajax/combobox/examples/programming/addremovedisableitemsclientside/defaultcs.aspx

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Jopito, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 11/7/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Here is the population of RadComboBox based on another RadComboBox
http://demos.telerik.com/aspnet-ajax/combobox/examples/functionality/multiplecomboboxes/defaultcs.aspx

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Jopito, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response