1

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

My Database table: enter image description here

My Asp Code:

<asp:Button runat="server" ID="btnReturn" Text="Return to Questions" PostBackUrl="~/Default.aspx" /> <asp:ListView runat="server" ID="lstQuestion"> <ItemTemplate> <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:RadioButtonList> <asp:TextBox runat="server" ID="txttest"></asp:TextBox> </ItemTemplate> </asp:ListView> <br /> <asp:Button runat="server" ID="btntest" Text="Get Result" OnClick="btntest_Click" /> 

The output in the browser

enter image description here

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.

4
  • Writes it to the database? I am not quite sure what you are trying ot do. Commented Jun 2, 2014 at 21:18
  • No just simple write the values that has been selected in a response.write(); Commented Jun 2, 2014 at 21:20
  • Can't you just use HttpResponse.Write() in the button Click event? (msdn.microsoft.com/en-us/library/1463ysyw(v=vs.110).aspx). Commented Jun 2, 2014 at 21:30
  • Problem i dont know how to get the values from the different text box and radiobuttonlist Commented Jun 2, 2014 at 21:37

1 Answer 1

2

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 } } } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.