C# – Using ASP.Net ListView.ExtractItemValues, how to get the selected item in a RadioButtonList in the ListViewDataItem


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.

Here is my markup:

<asp:ListView ID="lvQuiz" runat="server">
    <asp:PlaceHolder ID="itemplaceholder" runat="server"></asp:PlaceHolder>
<asp:Button ID="cmdSubmit" runat="server" Text="Submit" OnClick="cmdSubmit_Click" />

                <asp:Label ID="lblQuestionText" runat="server" Text='<%# Bind("Question.QuestionText") %>' />
            <asp:RadioButtonList ID="rblResponse" runat="server" DataTextField="ResponseText" DataValueField="Id" 
                DataSource='<%# Bind("Question.PossibleResponses") %>'>

And here is the code where I am trying to extract the values:

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 => x.QuestionText == itemValues["Question.QuestionText"])

    Q.UserResponses[myQuestion] = itemValues["Question.PossibleResponses"].SelectedItem

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?

Best Solution

Well, I ended up implementing an extension method for Control that implements a Recursive FindControl, as outlined in Steve Smith blog post on Recursive FindControl. As I only had two bindable controls that I cared about (Label and a ListControl), this ended up being good enough. Tightly coupled to the UI, but I don't know what else to do.