Array c#,

Posted on 2011-05-05
Last Modified: 2012-05-11
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 'B' combobox2 will show 'A','C' only.

Please help me with C# code example. Thank you.
Question by:suvmitra
    LVL 10

    Expert Comment

    You have to a autopostback on the control...And on click event
    LVL 26

    Expert Comment

    by:Anurag Thakur
    do the databind on combo box 2 but after doing the databind remove the value from the comboox
    LVL 10

    Expert Comment

    LVL 4

    Accepted Solution


    **** aspx *******
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
    <html xmlns="">
    <head runat="server">
        <title>Untitled Page</title>
        <form id="form1" runat="server">
            <asp:TextBox runat="server" ID="txtTextBox">
            <asp:DropDownList runat="server" ID="ddl1" AutoPostBack="true" 
                <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 runat="server" ID="ddl2">
    ********* 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)
            foreach (ListItem lstItem in ddl1.Items)
                if (!lstItem.Selected)

    Open in new window

    LVL 4

    Expert Comment

    ignore the asp:textbox
    LVL 9

    Author Closing Comment

    Excellent! Thank you.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Article by: Ivo
    Anonymous Types in C# by Ivo Stoykov Anonymous Types are useful when  we do not need to follow usual work-flow -- creating object of some type, assign some read-only values and then doing something with them. Instead we can encapsulate this read…
    This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now