Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Binding a radiobuttonlist to a filtered datatable?

Posted on 2006-03-29
Medium Priority
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

Accepted Solution

Havagan earned 2000 total points
ID: 16322885
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";



Author Comment

ID: 16322917
Awesome Paul thanks!!!!

Featured Post

Technology Partners: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Integration Management Part 2
Suggested Courses
Course of the Month10 days, 16 hours left to enroll

572 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