Listbox items depends on DropDown RRS feed

  • Question


    okay  I  Have have list box control and a Dropdown, and i would like to make that Listbox items depends on DropDown .

    In List box i am taking the data from Username column and drop-down from department column(Distinct) 


    Now i want like when ever i select department , it will show me only the username belongs to particular department in list box not everything.

    Can someone plz help me in this.

    • Moved by Bob Wu-MT Tuesday, October 18, 2011 10:12 AM ASP.Net (From:Visual C# General)
    Monday, October 17, 2011 5:52 PM


All replies

  • Welcome to MSDN Forums.

    Sorry, It's a DataGridView not a ListBox which you've been attached it's image.

    You can handle the ComboBox.SelectedIndex changed like below:

    void CB_SelectedIndexChanged(..)
      ((BindingSource)dataGridView1.DataSource).Filter = string.format("Department='{0}'",CB.SelectedValue);



    Monday, October 17, 2011 6:21 PM
  • i am sorry i put the image of my database.here is the image of the UI

    here is my asp.net code.

    <asp:Label ID="Label19" runat="server" Visible="False"  ></asp:Label>User Profiles</h2>

        <form id="form1">

              <asp:ScriptManager ID="ScriptManager1" runat="server">



        <div class="proalign">

         <br />


          <div class="tang">

               <asp:DropDownList ID="DropDownList1" runat="server" 

                DataSourceID="SqlDataSource2" DataTextField="Department"  AutoPostBack="true"



            <asp:SqlDataSource ID="SqlDataSource2" runat="server" 

                ConnectionString="<%$ ConnectionStrings:Event %>" 

                SelectCommand="SELECT DISTINCT [Department] FROM [UserProfile]">

            </asp:SqlDataSource> <br />

               <asp:ListBox ID="txtUserName" runat="server" 

                DataSourceID="SqlDataSource3" DataTextField="UserName"  AutoPostBack="true"

                                    DataValueField="UserName" Height="388px" Width="168px"></asp:ListBox>


                                <asp:SqlDataSource ID="SqlDataSource3" runat="server" 

                                    ConnectionString="<%$ ConnectionStrings:Event %>" 


                                    SelectCommand="SELECT [UserName] FROM [vw_aspnet_Users] ORDER BY [UserName]"></asp:SqlDataSource>                         

         <br />    





    Monday, October 17, 2011 6:45 PM
  • also Could you plz Provide me any sample template or anything link are using a such kind of pattern in a combo Box or anything.
    Monday, October 17, 2011 6:46 PM
  • Hi Akshat,

    According to your description, I find your topic is related to ASP.NET.You may post the thread in ASP.NET Forum. There are more experts in that forum so that you may get more useful help there.

    Thank you for your understanding.

    Bob Wu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, October 18, 2011 10:11 AM