Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing ASP.Net ListView.ExtractItemValues, how do I get the selected item in a RadioButtonList in the ListViewDataItem?
    primarykey
    data
    text
    <p>I'm attempting to iterate over the ListViewDataItems in an ASP.Net ListView, and use the ListView.ExtractItemValues to get the values from DataBoundControls. This works fine with ITextControls, but I am having difficulty getting the Selected Item from a RadioButtonList. </p> <p>Here is my markup:</p> <pre><code>&lt;asp:ListView ID="lvQuiz" runat="server"&gt; &lt;LayoutTemplate&gt; &lt;fieldset&gt; &lt;ul&gt; &lt;asp:PlaceHolder ID="itemplaceholder" runat="server"&gt;&lt;/asp:PlaceHolder&gt; &lt;/ul&gt; &lt;/fieldset&gt; &lt;asp:Button ID="cmdSubmit" runat="server" Text="Submit" OnClick="cmdSubmit_Click" /&gt; &lt;/LayoutTemplate&gt; &lt;ItemTemplate&gt; &lt;li&gt; &lt;fieldset&gt; &lt;legend&gt; &lt;asp:Label ID="lblQuestionText" runat="server" Text='&lt;%# Bind("Question.QuestionText") %&gt;' /&gt; &lt;/legend&gt; &lt;asp:RadioButtonList ID="rblResponse" runat="server" DataTextField="ResponseText" DataValueField="Id" DataSource='&lt;%# Bind("Question.PossibleResponses") %&gt;'&gt; &lt;/asp:RadioButtonList&gt; &lt;/fieldset&gt; &lt;/li&gt; &lt;/ItemTemplate&gt; </code></pre> <p></p> <p>And here is the code where I am trying to extract the values:</p> <pre><code>var Q = (Quiz)Session["Quiz"]; foreach (var item in lvQuiz.Items) { var itemValues = new OrderedDictionary(); lvQuiz.ExtractItemValues(itemValues, item, true); var myQuestion = Q.UserResponses.Keys .Where(x =&gt; x.QuestionText == itemValues["Question.QuestionText"]) .Single(); Q.UserResponses[myQuestion] = itemValues["Question.PossibleResponses"].SelectedItem } </code></pre> <p>My problem lies with that last line there. "Question.PossibleResponses" is bound to the RadioButtonList, but the value for itemValues["Question.PossibleResponses"] returns a list of ALL my RadioButtonList's options. How do I tell which one the user selected?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload