Array c#, asp.net

I have two combo boxes at my default.aspx page. in the page lode event i am populating combobox1 with say A,B,C.

What I need is..say user is selecting a value from combobox1 .. say 'B'..combobox2 will then reload its values except the value already chosen in combobox1..eg 'B'...so combobox2 will show 'A','C' only.

Please help me with C# code example. Thank you.
LVL 9
suvmitraAsked:
Who is Participating?
 
abhinaypCommented:

**** aspx *******

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox runat="server" ID="txtTextBox">
        </asp:TextBox>
        <asp:DropDownList runat="server" ID="ddl1" AutoPostBack="true" 
            onselectedindexchanged="ddl1_SelectedIndexChanged">
            <asp:ListItem Text=" -- Select One --" Value="0"></asp:ListItem>
            <asp:ListItem Text="Sample1" Value="1"></asp:ListItem>
            <asp:ListItem Text="Sample2" Value="2"></asp:ListItem>
            <asp:ListItem Text="Sample3" Value="3"></asp:ListItem>
        </asp:DropDownList>
        <asp:DropDownList runat="server" ID="ddl2">
        </asp:DropDownList>
    </div>
    </form>
</body>
</html>

********* c# **********


using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
       
    }
    protected void ddl1_SelectedIndexChanged(object sender, EventArgs e)
    {
        ddl2.Items.Clear();
        foreach (ListItem lstItem in ddl1.Items)
        {
            if (!lstItem.Selected)
                ddl2.Items.Add(lstItem);
        }
    }
}

Open in new window

0
 
GlobaLevelProgrammerCommented:
You have to a autopostback on the control...And on click event
0
 
Anurag ThakurTechnical ManagerCommented:
do the databind on combo box 2 but after doing the databind remove the value from the comboox
http://www.google.com/search?hl=en&source=hp&biw=1600&bih=842&q=combobox.items.remove&aq=0&aqi=g1&aql=&oq=combobox.items.re
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
GlobaLevelProgrammerCommented:
0
 
abhinaypCommented:
ignore the asp:textbox
0
 
suvmitraAuthor Commented:
Excellent! Thank you.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.