Binding a radiobuttonlist to a filtered datatable?

Posted on 2006-03-29
Last Modified: 2011-09-20

I have a datatable that I would like to bind to a radiobuttonlist; however, I don't want all of the items to show up, so I filtered the datatable but this doesn't seem to make a difference when binding it to the radio list.  Here is an example of my table:

1              Greater Admin    Admin
2              Admin                Admin
3              Read                  Maintenance
4              Write                 Maintenance
5              Alter                  Maintenance

plus many more.  In this case, I want only the role_names for the "maintenance" area, with the value being the role_id.  Here is my code (roleOptions is my datatable):

RadioButtonList rdoList = new RadioButtonList();
rdoList.RepeatDirection = RepeatDirection.Horizontal;
rdoList.DataSource = roleOptions;
rdoList.DataValueField = "role_id";
rdoList.DataTextField = "role_name";

It doesn't limit it to just the maintenance roles.  It shows:

*Greater Admin  *Admin  *Read  *Write  *Alter

when I want it just to show:

 *Read  *Write  *Alter

I am unsure how to make this easy.   I tried a hashtable and binding it and that worked awesome, but it put it in any order it wanted, which I couldn't do.  Then I tried a SortedList, but you can't control how it sorts so I dumped that idea too.  Then I tried the ArrayList, but I couldn't have different value and text fields with that.  So now I'm trying the datatable.  I can't limit the data to maintenance when I retrieve it because I will be using it for other things.

Thanks for the help.
Question by:dentyne
    LVL 6

    Accepted Solution

    The .Select method returns a row collection but doesn't filter the datatable which you're binding to the radiobuttonlist.

    Try using a row filter instead.

    roleOptions.DefaultView.RowFilter = " area = 'Maintenance' ";
    rdoList.DataSource = roleOptions.DefaultView;
    rdoList.DataValueField = "role_id";
    rdoList.DataTextField = "role_name";


    LVL 1

    Author Comment

    Awesome Paul thanks!!!!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
    Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    759 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

    12 Experts available now in Live!

    Get 1:1 Help Now