Get Data from Controls created by listview?

Hello and thanks for taking your time and reading this question.

My Database table:

My Asp Code:

<asp:Button runat="server" ID="btnReturn" Text="Return to Questions" PostBackUrl="~/Default.aspx" />
<asp:ListView runat="server" ID="lstQuestion">
        <h1><%# Eval("Title") %></h1>
        <asp:RadioButtonList runat="server" id="rblAnswers">
            <asp:ListItem Text="yes"></asp:ListItem>
            <asp:ListItem Text="no"></asp:ListItem>
            <asp:ListItem Text="Maybe"></asp:ListItem>
        <asp:TextBox runat="server" ID="txttest"></asp:TextBox>
<br />
<asp:Button runat="server" ID="btntest" Text="Get Result" OnClick="btntest_Click" />

The output in the browser

What I want to achive is: If the User press the btntest and the page looks like the one above. A simple response.write() (to start with) shall write the : no - Coment1 - yes - Coment 2.

Basic it write what has been select and coments if something is typed.

I hope you understand and sorry for my english.


You need to use find control to reference the controls inside the ListView. However if the controls you want to access are part of the ListView ItemTemplate, then you need to iterate through each item and find the controls for that item.

I wrote this without an IDE, it should be something like this:

//Iterate through the rows of the List View
foreach (item ListViewItem in lstView.Items)
     //If the control is a data item
     if (item.ItemType = ListViewItemType.DataItem)
          RadioButtonList  rbl = item.FindControl("rblAnswers") as RadioButtonList;
          if(rbl != null)
          //do something

          TextBox tb = item.FindControl("txttest") as TextBox;
          if(tb != null)
          //do something    

Need Your Help

Most efficient way to print all variations of a String?

java arrays string

If I have a 7 word String (I like it when it rains hard) and I want to print every variation of it that is

Data serialization

objective-c cocoa networking serialization communication-protocol

I've got an Objective-C/cocoa based application that I'm working on. This app is client&lt;->server. Currently, the communcation protocol is based upon some fairly simple XML. While XML works for t...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.