Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7723897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:33:33+00:00 2026-06-01T04:33:33+00:00

I have a drop down list box like following. Under some condition, in the

  • 0

I have a drop down list box like following. Under some condition, in the databound event I want to remove the items whose bitActive is set to 0 (inactive). I did not put a WHERE bitAcive!=0 in the selectCommand, because I only want to remove them under some conditions. Is there any way I could iterate the items and check the value of bitActive?

<tr>
            <td width="30%" align="right">Location<span class="littlefont">*</span></td>
            <td width="70%" align="left">
                <asp:DropDownList ID="ddlLocation" runat="server" 
                    DataSourceID="SqlDSLocation" DataTextField="txtRefLocation_Name" 
                    DataValueField="intRefLocation_ID" ondatabound="ddlLocation_DataBound">
                </asp:DropDownList>
                <asp:SqlDataSource ID="SqlDSLocation" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:SPRConnectionString %>" 
                    SelectCommand="SELECT DISTINCT [intRefLocation_ID], [txtRefLocation_Name], [location], [bitActive] FROM [tblRefLocation] ORDER BY [intRefLocation_ID]">
                </asp:SqlDataSource>
            </td>
        </tr> 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T04:33:34+00:00Added an answer on June 1, 2026 at 4:33 am

    In codebehind you can call the SQLDataSource.Select() method:

    System.Data.DataView dv = (System.Data.DataView)SqlDSLocation.Select(DataSourceSelectArguments.Empty);
    

    And then iterate through the rows returned, finding the “bitActive” rows who are set to zero and removing them from your DropDownList (code sort of hacked from the example linked above):

    foreach(System.Data.DataRow row in dv.Table.Rows)
    {
        // This is approximate logic, tailor this to fit your actual data
        if (row["bitActive"].ToString() == "False")
        {
            ddlLocation.Items.Remove(row["intRefLocation_ID"].ToString());
        }
    }
    

    Note that this is not removing these rows from your SQL table. Make sure you don’t databind your DropDownList again after this – otherwise all the stuff you just removed will return.

    EDIT: For a more efficient and elegant solution, see James Johnson’s answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to have a drop down box that has a list of different
I'd like to add a drop-down list to a Windows application. It will have
I have a list of Payees in a drop down box on my form.
I have a drop down list's select tag that looks like this: <select name=MyName
I have a dialog box with a drop down menu like this: Object[] possibilities
Is there an alternative to the drop down list like a Select-Box in MVC2?
I have a drop down list where users can select a theme for the
I have a drop down list that has options that need to be passed
I have a drop down list that triggers an updatepanel when the index is
I have a drop-down list hardcoded in an MVC View User Control page and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.