Replace radiobuttonlist  with checkbox list at runtime

mmalik15
mmalik15 used Ask the Experts™
on
My quiz engine is implemented like this

My table is like this
Id    Question       Choices       CorrectAnswer                  Type
1      xxxx          a,b,c,d          a     choices are splitted by comma.      Rbutton,Checkbox
...
And  ListView is designed like this:
<asp:ListView... ItemPlaceHolder = "trPlaceHolder" DataKeys="Id">
 <LayoutTemplate>
  <table width=100%>
   <tr>
    <th>Question</th>
    <th>Choices</th>
   </tr>
  </table>
 </LayoutTemplate>
 
 <ItemTemplate>
  <tr>
   <td><%#Eval("Question")%></td>
   <td>
    <asp:RadioButtonList id = "rbtChoices" runat="server" DataSource='<%#AutoConvert(Eval("trPlaceHolder"))%>'>
   </td>
  </tr>
 </ItemTemplate>
</asp:ListView...>
Page_Load event is as follows
private void Page_Load(....)
{
 if(!IsPostBack)
 {
  ListView1.DataSource = xxx;
  ListView1.DataBind();
 }
}
AutoConvert function should be this:
protected string[]AutoConvert(object values)
{
 return values.ToString().Split(',');
}
There is a button out of ListView, in the click event, we loop each item of the listview and use FindControl to get the selected radio's Text:
private void Button_Click(....)
{
 foreach(ListViewDataItem item in ListView1.Items)
 {
  DataRowView dv = (DataRowView)item;
  string correctValue = dv.Row["Your ColumnName here..."];
  RadioButtonList rbLst = (RadioButtonList)item.FindControl("rbtChoices");
  if(rbList.SelectedItem.Text == correctValue)
  {
   //do what we like here...
  }
 
}

how can I replace  radiobutton list with checkbox list if question type is checkbox and viceversa

thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
you can toggle visibility http://www.dotnetperls.com/visible depending on the type.

if type == checkbox...
checkboxlist.visible = true
radiolist.visible = false
.....
else if type == radio
checkboxlist.visible = false
radiolist.visible = true
....

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial