By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,307 Members | 1,590 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,307 IT Pros & Developers. It's quick & easy.

Argh! Trouble getting values from textbox in a Repeater

P: n/a
OK, never mind my last post. It was easy enough to refer to the table the
repeater is bound to, but I made a big, incorrect assumption in that post.

In my last post I thought I was successfully getting values from the
textboxes in my repeater. It turns out I am not and I can't see what I'm
doing wrong. I've had this problem before and just ended up taking a
different route to avoid it. Now I REALLY need to figure out what I'm doing
wrong.

This is for a configurable web survey form that is driven by SQL server
tables.

The repeater is coded like this:

<asp:repeater id=rptQuestions runat="server" DataSource="<%# DsQuestions1
%>" DataMember="questions">
<ItemTemplate>
<b>
<%#Convert.ToString(DataBinder.Eval(Container.Data Item, "qNum"))%>
. </b></td>
<%# DataBinder.eval(Container.Dataitem, "question") %>
</td>
<br>
<asp:TextBox ID="ans" Runat="server" />
</ItemTemplate>
<HeaderTemplate>
<b>Please answer as concisely as possible </b>
<br>
<br>
</HeaderTemplate>
<FooterTemplate>
</FooterTemplate>
<SeparatorTemplate>
<br />
<hr>
<br />
</SeparatorTemplate>
</asp:repeater>
-----------------------------------
It renders as I would expect using the values from the database. I also have
a "Submit" button. This is the click event:

Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSubmit.Click
Dim strAns As String, i As Int16, dtQs As DataTable
Dim aAns(rptQuestions.Items.Count - 1, 2) As String

dtQs = DsQuestions1.Tables("questions")

For i = 0 To rptQuestions.Items.Count - 1
Dim currentTextBox As TextBox _
= CType(rptQuestions.Items(i).FindControl("Ans"),
WebControls.TextBox)
'load up an array with answers and corresponding question IDs
aAns(i, 0) = currentTextBox.Text
aAns(i, 1) = Convert.ToString(dtQs.Rows(i)("qID"))
Next
End Sub
------------------------------------

So when I look at the values in my array, the values from the datatable (the
"qID" value) is being correctly assigned. My problem is the
currentTextBox.text is always = "" even when there is text in the box. Can
anyone tell me why I'm not getting the entered values? Please?

Thanks!

Matt
Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
FYI - the problem was I was not putting the repeater.databind inside a If
Not IsPostBack condition. Hope that helps if anyone eles hits this issue.

Matt

MattB wrote:
OK, never mind my last post. It was easy enough to refer to the table
the repeater is bound to, but I made a big, incorrect assumption in
that post.

In my last post I thought I was successfully getting values from the
textboxes in my repeater. It turns out I am not and I can't see what
I'm doing wrong. I've had this problem before and just ended up
taking a different route to avoid it. Now I REALLY need to figure out
what I'm doing wrong.

This is for a configurable web survey form that is driven by SQL
server tables.

The repeater is coded like this:

<asp:repeater id=rptQuestions runat="server" DataSource="<%#
DsQuestions1 %>" DataMember="questions">
<ItemTemplate>
<b>
<%#Convert.ToString(DataBinder.Eval(Container.Data Item, "qNum"))%>
. </b></td>
<%# DataBinder.eval(Container.Dataitem, "question") %>
</td>
<br>
<asp:TextBox ID="ans" Runat="server" />
</ItemTemplate>
<HeaderTemplate>
<b>Please answer as concisely as possible </b>
<br>
<br>
</HeaderTemplate>
<FooterTemplate>
</FooterTemplate>
<SeparatorTemplate>
<br />
<hr>
<br />
</SeparatorTemplate>
</asp:repeater>
-----------------------------------
It renders as I would expect using the values from the database. I
also have a "Submit" button. This is the click event:

Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSubmit.Click
Dim strAns As String, i As Int16, dtQs As DataTable
Dim aAns(rptQuestions.Items.Count - 1, 2) As String

dtQs = DsQuestions1.Tables("questions")

For i = 0 To rptQuestions.Items.Count - 1
Dim currentTextBox As TextBox _
= CType(rptQuestions.Items(i).FindControl("Ans"),
WebControls.TextBox)
'load up an array with answers and corresponding question
IDs aAns(i, 0) = currentTextBox.Text
aAns(i, 1) = Convert.ToString(dtQs.Rows(i)("qID"))
Next
End Sub
------------------------------------

So when I look at the values in my array, the values from the
datatable (the "qID" value) is being correctly assigned. My problem
is the currentTextBox.text is always = "" even when there is text in
the box. Can anyone tell me why I'm not getting the entered values?
Please?

Thanks!

Matt


Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.