• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 219
  • Last Modified:

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.
0
suvmitra
Asked:
suvmitra
1 Solution
 
GlobaLevelCommented:
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
 
GlobaLevelCommented:
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
abhinaypCommented:
ignore the asp:textbox
0
 
suvmitraAuthor Commented:
Excellent! Thank you.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now