By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,795 Members | 1,235 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,795 IT Pros & Developers. It's quick & easy.

Multiple Radio Button List in Repeater Control

P: 4
Hi, I am trying to figure out if this is possible. I need to display 4 radio buttons next to a question then 3 radio buttons after. The 2 different group radio buttons and questions are coming from a database.

I have the questions being displayed right now using a repeater control but I am having an issue making 4 and 3 radio buttins per question for multiple questions. However some questions have sub questions so the parent question doesn't have the radio buttons. Is this possible?

E.G.
- radio|radio|radio|radio|question|radio|radio|radio

- question

- radio|radio|radio|radio|Sub question|radio|radio|radio
Mar 7 '08 #1
Share this Question
Share on Google+
4 Replies


nateraaaa
Expert 100+
P: 663
Hi, I am trying to figure out if this is possible. I need to display 4 radio buttons next to a question then 3 radio buttons after. The 2 different group radio buttons and questions are coming from a database.

I have the questions being displayed right now using a repeater control but I am having an issue making 4 and 3 radio buttins per question for multiple questions. However some questions have sub questions so the parent question doesn't have the radio buttons. Is this possible?

E.G.
- radio|radio|radio|radio|question|radio|radio|radio

- question

- radio|radio|radio|radio|Sub question|radio|radio|radio
This is possible. You need to figure out the logic to make this work. I believe whatever code you write will need to be in the repeaters ItemDataBound event. This way you can identify what to display (question or question - sub question).

Nathan
Mar 7 '08 #2

P: 4
Ya, that's the key, what is the logic to it, what do I need to use to make this happen?
Mar 10 '08 #3

Frinavale
Expert Mod 5K+
P: 9,731
Ya, that's the key, what is the logic to it, what do I need to use to make this happen?
You need to implement this logic when you are retrieving the questions from your database.
Mar 10 '08 #4

P: 4
I'm not sure you guys understand, so here is my code. and I need to display radio buttons for all parent questions unless it has a child question

Page code:
Expand|Select|Wrap|Line Numbers
  1. <table width="100%" cellpadding="0" cellspacing="0" border="0">
  2.     <asp:Repeater runat="server" ID="RepWorkArea" OnItemDataBound="ShowQuestions">
  3.         <ItemTemplate>
  4.             <tr>
  5.                 <td colspan="3">
  6.                     <h4><%# ((DataRowView)Container.DataItem)["WorkArea"]%></h4>
  7.                 </td>
  8.             </tr>
  9.             <asp:Repeater ID="RepQuestions" OnItemDataBound="ShowSubQuestions" runat="server">
  10.                 <itemtemplate> 
  11.                 <tr>
  12.                     <td width="90px"><asp:RadioButtonList ID="radQuestionList" runat="server" DataSourceID="SqlDataSource1" DataValueField="SkillImportanceID" OnSelectedIndexChanged="btnViewSkill_Click" RepeatDirection="Horizontal" DataTextField="empty" RepeatLayout="flow"/></td>
  13.                     <td width="*"><b><%# (Container.ItemIndex + 1) %>.</b> <%# ((DataRowView)Container.DataItem)["Question"]%></td>
  14.                     <td width="70px" align="right"><asp:RadioButtonList ID="radSubQuestionList" runat="server" DataSourceID="SqlDataSource2" DataValueField="AnswerID" RepeatDirection="Horizontal" DataTextField="empty" RepeatLayout="flow"/></td>
  15.                 </tr>
  16.                 <tr>
  17.                     <td colspan="3" align="left">
  18.                         <table width="100%"  cellpadding="0" cellspacing="0" border="0">
  19.                             <asp:repeater id="RepSubQuestions" runat="server"> 
  20.                                 <itemtemplate>
  21.                                 <tr>
  22.                                     <td width="90px">
  23.                                         <asp:RadioButtonList ID="radQuestionList" runat="server" DataSourceID="SqlDataSource1" DataValueField="SkillImportanceID" OnSelectedIndexChanged="btnViewSkill_Click" RepeatDirection="Horizontal" DataTextField="empty" RepeatLayout="flow"/>
  24.                                     </td>
  25.                                     <td width="*">
  26.                                         <div id="SubQuestions">
  27.                                             <li class="bold"><%# DataBinder.Eval(Container.DataItem, "[\"Question\"]")%></li>
  28.                                         </div>
  29.                                     </td>
  30.                                     <td width="70px" align="right">
  31.                                         <asp:RadioButtonList ID="radSubQuestionList" runat="server" DataSourceID="SqlDataSource2" DataValueField="AnswerID" RepeatDirection="Horizontal" DataTextField="empty" RepeatLayout="flow"/>
  32.                                     </td>
  33.                                 </tr>
  34.                                 </itemtemplate> 
  35.                             </asp:repeater>   
  36.                         </table>
  37.                     </td>
  38.                 </tr>
  39.                 </itemtemplate> 
  40.             </asp:Repeater>
  41.         </ItemTemplate>
  42.     </asp:Repeater>
  43. </table>
  44.  
//Code Behind

Expand|Select|Wrap|Line Numbers
  1. private SqlConnection connString = new SqlConnection(WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString.ToString());
  2.  
  3.     protected void Page_Load(object sender, EventArgs e)
  4.     {
  5.         string strSql;
  6.         DataSet ds = new DataSet();
  7.         strSql = "select distinct A.* from WorkAreas as A right Join EvaluationQuestions AS B on a.WorkAreaId = B.WorkAreaID AND B.EvaluationID = 1 Order By A.SortOrder";
  8.         SqlDataAdapter daWorkAreas = new SqlDataAdapter(strSql, connString);
  9.         daWorkAreas.Fill(ds, "WorkAreas");
  10.         strSql = "select * from EvaluationQuestions WHERE ParentId = -1 AND Active = 1 AND EvaluationID = 1 Order By EvaluationQuestionID";
  11.         SqlDataAdapter daEvaluationQuestions = new SqlDataAdapter(strSql, connString);
  12.         daEvaluationQuestions.Fill(ds, "EvaluationQuestions");
  13.         strSql = "select * from EvaluationQuestions WHERE Active = 1 AND EvaluationID = 1 Order By EvaluationQuestionID";
  14.         SqlDataAdapter daSubQuestions = new SqlDataAdapter(strSql, connString);
  15.         daSubQuestions.Fill(ds, "SubQuestions");
  16.         DataRelation rel = new DataRelation("QuestionsRel",ds.Tables["WorkAreas"].Columns["WorkAreaID"], ds.Tables["EvaluationQuestions"].Columns["WorkAreaID"],false);
  17.         ds.Relations.Add(rel);
  18.         DataRelation rel2 = new DataRelation("QuestionsRel2", ds.Tables["EvaluationQuestions"].Columns["EvaluationQuestionID"], ds.Tables["SubQuestions"].Columns["ParentID"], false);
  19.         ds.Relations.Add(rel2);
  20.         RepWorkArea.DataSource = ds.Tables["WorkAreas"].DefaultView;
  21.         RepWorkArea.DataBind();
  22.         connString.Close();
  23.  
  24.     }
  25.  
  26.     public void ShowQuestions(Object sender, RepeaterItemEventArgs e)
  27.     {
  28.         if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
  29.         {
  30.             ((Repeater)e.Item.FindControl("RepQuestions")).DataSource =
  31.             ((DataRowView)e.Item.DataItem).CreateChildView("QuestionsRel");
  32.             ((Repeater)e.Item.FindControl("RepQuestions")).DataBind();
  33.         }
  34.     }
  35.  
  36.     public void ShowSubQuestions(Object sender, RepeaterItemEventArgs e)
  37.     {
  38.         if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
  39.         {
  40.             ((Repeater)e.Item.FindControl("RepSubQuestions")).DataSource =
  41.             ((DataRowView)e.Item.DataItem).CreateChildView("QuestionsRel2");
  42.             ((Repeater)e.Item.FindControl("RepSubQuestions")).DataBind();
  43.         }
  44.     }
  45.  
Mar 10 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.