James Wilson
James Wilson

Reputation: 5150

Dynamic set of radio buttons

On a page I have an ID in the query string. From this ID I need to query my lookup table and get a list of anything matching the id in this table.

The table looks like below:

id  workFlowID  nextStepID
2       27          28
3       28          29
4       27          29

If the query string has the Id of 27 then it would return only two results.

How do I create a dynamic radio button for those two results?

Below are the two tables I will be using.

select * from jm_AccountworkFlowDetail wfd
left join jm_accountworkflowsteps wfs on wfs.workFlowID = wfd.workID

Here is what the above query would return:

workID  name               status   nextStep    id  workFlowID  nextStepID
27      BaseLevelWFI       NULL     NULL        2      27          28
27      BaseLevelWFI       NULL     NULL        4      27          29
28      NextStepBaseLevel  NULL     NULL        3      28          29
29      AfterNextStepBase  NULL     NULL        NULL   NULL        NULL

wfd contains the first 4 colums, contains the name to be used as well. wfs is the look up table and is how i will tell if an item in the first table should have radio buttons.

It is possible for a work item to not have any next step and won't return any results so it should have any radio buttons. Some should return one, and some will return more than one.

What I need is a dynamic list of radio buttons with the text to be set as the name and the value to be set as the workID.

Can this be done outside of the code behind page?

Upvotes: 0

Views: 1107

Answers (3)

Jan Sommer
Jan Sommer

Reputation: 3808

If you want to do it without a code behind take a look at SqlDataSource. Here's a link that includes how to read from query string: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.querystringparameter.querystringfield.aspx

Then bind the result to your RadioButtonList.

Upvotes: 1

dav_i
dav_i

Reputation: 28157

RadioButtonList has a DataSource property which you can bind to.

Your aspx side would then have

<asp:RadioButtonList runat="server" ID="radioButtonList" />

and the aspx.cs side

this.radioButtonList.DataSource = myDataSource;
this.radioButtonList.DataBind();

Other than that I'm not entirely clear on what you want. My other advice would be to use something like LINQ-to-SQL so you can use all the LINQy goodness of C#

Upvotes: 2

Polly Shaw
Polly Shaw

Reputation: 3237

You could filter the dataset that you've returned using

"WorkFlowID = " + Request.QueryString["ID"] + " and NextStepID is not null" 

(Although not exactly like that, because that's vulnerable to SQL Injection.)

and then bind the filtered dataset to an ASP.NET Repeater Control

<asp:Repeater id="cdcatalog" runat="server">


<ItemTemplate>
    <%# DataBinder.Eval(Container.DataItem, "name") %>
    <input type='radio' name='nextStepId' 
         value='<%# DataBinder.Eval(Container.DataItem, "nextStepID") %>'/>
    <br/>
</ItemTemplate>
</asp:Repeater>

Upvotes: 0

Related Questions