Multiple Radio Button List in Repeater Control

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • CURTISLESPERANCE
    New Member
    • Mar 2008
    • 4

    Multiple Radio Button List in Repeater Control

    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|rad io|radio|questi on|radio|radio| radio

    - question

    - radio|radio|rad io|radio|Sub question|radio| radio|radio
  • nateraaaa
    Recognized Expert Contributor
    • May 2007
    • 664

    #2
    Originally posted by CURTISLESPERANC E
    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|rad io|radio|questi on|radio|radio| radio

    - question

    - radio|radio|rad io|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

    Comment

    • CURTISLESPERANCE
      New Member
      • Mar 2008
      • 4

      #3
      Ya, that's the key, what is the logic to it, what do I need to use to make this happen?

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Originally posted by CURTISLESPERANC E
        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.

        Comment

        • CURTISLESPERANCE
          New Member
          • Mar 2008
          • 4

          #5
          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:
          [CODE=asp]
          <table width="100%" cellpadding="0" cellspacing="0" border="0">
          <asp:Repeater runat="server" ID="RepWorkArea " OnItemDataBound ="ShowQuestions ">
          <ItemTemplate >
          <tr>
          <td colspan="3">
          <h4><%# ((DataRowView)C ontainer.DataIt em)["WorkArea"]%></h4>
          </td>
          </tr>
          <asp:Repeater ID="RepQuestion s" OnItemDataBound ="ShowSubQuesti ons" runat="server">
          <itemtemplate >
          <tr>
          <td width="90px"><a sp:RadioButtonL ist ID="radQuestion List" runat="server" DataSourceID="S qlDataSource1" DataValueField= "SkillImportanc eID" OnSelectedIndex Changed="btnVie wSkill_Click" RepeatDirection ="Horizontal " DataTextField=" empty" RepeatLayout="f low"/></td>
          <td width="*"><b><% # (Container.Item Index + 1) %>.</b> <%# ((DataRowView)C ontainer.DataIt em)["Question"]%></td>
          <td width="70px" align="right">< asp:RadioButton List ID="radSubQuest ionList" runat="server" DataSourceID="S qlDataSource2" DataValueField= "AnswerID" RepeatDirection ="Horizontal " DataTextField=" empty" RepeatLayout="f low"/></td>
          </tr>
          <tr>
          <td colspan="3" align="left">
          <table width="100%" cellpadding="0" cellspacing="0" border="0">
          <asp:repeater id="RepSubQuest ions" runat="server">
          <itemtemplate >
          <tr>
          <td width="90px">
          <asp:RadioButto nList ID="radQuestion List" runat="server" DataSourceID="S qlDataSource1" DataValueField= "SkillImportanc eID" OnSelectedIndex Changed="btnVie wSkill_Click" RepeatDirection ="Horizontal " DataTextField=" empty" RepeatLayout="f low"/>
          </td>
          <td width="*">
          <div id="SubQuestion s">
          <li class="bold"><% # DataBinder.Eval (Container.Data Item, "[\"Question\"]")%></li>
          </div>
          </td>
          <td width="70px" align="right">
          <asp:RadioButto nList ID="radSubQuest ionList" runat="server" DataSourceID="S qlDataSource2" DataValueField= "AnswerID" RepeatDirection ="Horizontal " DataTextField=" empty" RepeatLayout="f low"/>
          </td>
          </tr>
          </itemtemplate>
          </asp:repeater>
          </table>
          </td>
          </tr>
          </itemtemplate>
          </asp:Repeater>
          </ItemTemplate>
          </asp:Repeater>
          </table>
          [/CODE]

          //Code Behind

          [CODE=cpp]
          private SqlConnection connString = new SqlConnection(W ebConfiguration Manager.Connect ionStrings["ConnectionStri ng"].ConnectionStri ng.ToString());

          protected void Page_Load(objec t sender, EventArgs e)
          {
          string strSql;
          DataSet ds = new DataSet();
          strSql = "select distinct A.* from WorkAreas as A right Join EvaluationQuest ions AS B on a.WorkAreaId = B.WorkAreaID AND B.EvaluationID = 1 Order By A.SortOrder";
          SqlDataAdapter daWorkAreas = new SqlDataAdapter( strSql, connString);
          daWorkAreas.Fil l(ds, "WorkAreas" );
          strSql = "select * from EvaluationQuest ions WHERE ParentId = -1 AND Active = 1 AND EvaluationID = 1 Order By EvaluationQuest ionID";
          SqlDataAdapter daEvaluationQue stions = new SqlDataAdapter( strSql, connString);
          daEvaluationQue stions.Fill(ds, "EvaluationQues tions");
          strSql = "select * from EvaluationQuest ions WHERE Active = 1 AND EvaluationID = 1 Order By EvaluationQuest ionID";
          SqlDataAdapter daSubQuestions = new SqlDataAdapter( strSql, connString);
          daSubQuestions. Fill(ds, "SubQuestions") ;
          DataRelation rel = new DataRelation("Q uestionsRel",ds .Tables["WorkAreas"].Columns["WorkAreaID "], ds.Tables["EvaluationQues tions"].Columns["WorkAreaID "],false);
          ds.Relations.Ad d(rel);
          DataRelation rel2 = new DataRelation("Q uestionsRel2", ds.Tables["EvaluationQues tions"].Columns["EvaluationQues tionID"], ds.Tables["SubQuestio ns"].Columns["ParentID"], false);
          ds.Relations.Ad d(rel2);
          RepWorkArea.Dat aSource = ds.Tables["WorkAreas"].DefaultView;
          RepWorkArea.Dat aBind();
          connString.Clos e();

          }

          public void ShowQuestions(O bject sender, RepeaterItemEve ntArgs e)
          {
          if (e.Item.ItemTyp e == ListItemType.It em || e.Item.ItemType == ListItemType.Al ternatingItem)
          {
          ((Repeater)e.It em.FindControl( "RepQuestions") ).DataSource =
          ((DataRowView)e .Item.DataItem) .CreateChildVie w("QuestionsRel ");
          ((Repeater)e.It em.FindControl( "RepQuestions") ).DataBind();
          }
          }

          public void ShowSubQuestion s(Object sender, RepeaterItemEve ntArgs e)
          {
          if (e.Item.ItemTyp e == ListItemType.It em || e.Item.ItemType == ListItemType.Al ternatingItem)
          {
          ((Repeater)e.It em.FindControl( "RepSubQuestion s")).DataSou rce =
          ((DataRowView)e .Item.DataItem) .CreateChildVie w("QuestionsRel 2");
          ((Repeater)e.It em.FindControl( "RepSubQuestion s")).DataBind() ;
          }
          }
          [/CODE]

          Comment

          Working...