Best design for RadioButtonList usage

I have a problem and i would like to learn the correct way to solve this.

I have a Data Objeckt

class LinkHolder {
    public string Text;
    public string Link;

I would like to present to the user a RadioButton list that uses the LinkHolder.Text value as descriptive text. Then on the postback, i would like to do a

Server.Transfer( LinkHolder.Link ) 

on the corresponding Link.

I am unsure what is the best/most correct way to do this. Any hints would be appreciated.


You need to set DataTextField and DataValueField on your RadioButtonList. Then the correct values should show up.

You can try to cast the selectedItem into a LinkHolder.

Your method should work. I think you should use accessors in your class though

class LinkHolder {
    public string Text { get; set;}
    public string Link { get; set;}

Bind your RadioButtonList to a f.ex. List<LinkHolder>

Why would you use a radiobuttonlist instead of just listing out your Links as Hyperlinks instead of having to use Server.Transfer?

the Class LinkHolder was just a short-form example. I do have accessors in the real class. The radiobuttons was a design choice, so im going with them.

In my tests, it would print the name of the class, and not the Text Property, when i used List<LinkHolder> as a DataSource. I don't know how/if you can specify a property the RadioButtonList should print.

It is also my understanding that if I use List<LinkHolder> as a Datasource I will not get a LinkHolder object back, when i ask for SelectedItem. I will instead get a ListItem.

Any good workaround to that?

Need Your Help

Rss Feed reader: SyndicationFeed way of programming

xml rss syndication

I'm currently developing an MVC project which contains an RSS feed reader.

Perl: array reference versus anonymous array

arrays perl

This may be a silly question... The following code outputs the contents of @arrayref and @arraycont respectively. Note the difference between them and the way the values of them are assigned. I kno...