![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
![]() |
| 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 | |||