Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - Dynamically setting RadioButtonList item as selected

Reply
 
Old 12-06-2008   #1 (permalink)
Adrian227


 
 

Dynamically setting RadioButtonList item as selected

This seems so trivial but I've spent the best part of a day trying to
solve. Please help!

I have a radiobuttonlist control on a web page with a DataSourceID set
to a stored procedure

<asp:RadioButtonList ID="RadioButtonList1" runat="server"
AppendDataBoundItems="false"
DataSourceID="SQLDataSource1" DataTextField="Text"
EnableViewState="true">
</asp:RadioButtonList>

It lists possible answers to a question. Think multiple choice exam;
select radio button to make your selection.

On the page I have Previous and Next buttons to scroll through
questions. These record the selected item in the database and display
the previous or next question as appropriate. No problem with any of
this.

I want the page to display the item they chose if the user views a
question already answered. I successfully retrieve the data item from
the database but I get an out of range error

"Index was out of range. Must be non-negative and less than the size
of the collection"

when i try

RadioButtonList1.Items(nUserChoice).Selected = True

If I comment out this line, all choices are displayed and I have tried
entering constant values of 0 and 1 in the above line of code but the
same error message appears.

I am attempting this action in the onclick event of the button after
rebinding the radiobuttonlist control, i.e.

RadioButtonList1.Items.Clear()
SQLDataSource1.SelectParameters("TIID").DefaultValue = TIID
SQLDataSource1.SelectParameters("QID").DefaultValue = QID
SQLDataSource1.DataBind()
RadioButtonList1.Items(nUserChoice).Selected = True

As I said, the data displays and behaves correctly otherwise. I must
be doing something stupid but I just can't see it.




My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
rename-item, move-item and special chars. PowerShell
Copy-Item : Container cannot be copied onto existing leaf item. PowerShell
Dynamically populate unattend.xml Vista installation & setup
Creating a hashtable dynamically PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46