I am retrieving data from a Stored Procedure and using it to populate a list of Questions using the ASP.Net Repeater like shown below.
It works great when all the questions are of the same type. But I now would like to have two different type of questions that won’t be known until runtime.
For example one will just have Yes or No Radio boxes while another will have a 5 Radio Boxes that allow the end user to rate something from 1 -5.
There will be a field in the data returned from the Store Procedure that will identify which type of Question it is and I would like to read that value at runtime and then display the appropriate HTML.
It looks like I should be using the ItemDataBound Event of the Repeater but I can’t figure out how to do what I want?
<asp:Panel ID="pnlQuestions" runat="server">
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="DBDataSource"
onitemdatabound="Repeater1_ItemDataBound">
<ItemTemplate>
<div class="Question">
/*The HTML that is written here should depend on the value
in one of the fields returned from the Stored Procedure*/
</div>
</ItemTemplate>
<FooterTemplate>
<div id="Footer">
<label for="AdditionalCommentsText" class="AdditionalCommentsLabel">Are there any additional comments or referrals you can provide at this time?</label>
<textarea id=""AdditionalCommentsText" class="AdditionalCommentsText" cols="80" rows="3" name="Q<%# DataBinder.Eval(Container.DataItem, "ID") %>AddtlComments"></textarea>
<asp:Button class="SubmitButton" runat="server" Text="Submit" />
</div>
</FooterTemplate>
</asp:Repeater>
<asp:SqlDataSource ID="DBDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:connString %>"
SelectCommand="usp_GetActiveQuestions" SelectCommandType="StoredProcedure">
</asp:SqlDataSource>
</asp:Panel>
1 Answer