Howto Add Data in Repeater and read it in code-behind ?

R

Radu

Hi. I have the following puzzle:
I have in the DB a table name "Login_QAByPIN". In it I'll store, for
identification purposes, 6 questions with 6 answers for each
registered pin. On the registration page, I have the following HTML:

<asp:repeater ID="rptQA" runat="server">
<ItemTemplate>
<tr>
<td><%# Container.DataItem("Q") %></td> <td><asp:TextBox
ID="txtAnswer" runat="server" Width="98%"></asp:TextBox></td> </
tr>
</ItemTemplate>
</asp:repeater>

On registration, the user should be able to enter/edit the answers (in
txtAnswer) and on cmdRegister_Click I want to update my
"Login_QAByPIN" table. The code would be (SNIP):

For intCount = 1 To rptQA.Items.Count
cmd = New SqlCommand(strSprocName, cnSQL)
cmd.CommandType = CommandType.StoredProcedure

objSqlParam = New SqlParameter("@PIN", SqlDbType.NVarChar)
objSqlParam.Value = m_strPIN
cmd.Parameters.Add(objSqlParam)

objSqlParam = New SqlParameter("@QuestionID", SqlDbType.NVarChar)
objSqlParam.Value = intCount
cmd.Parameters.Add(objSqlParam)

objSqlParam = New SqlParameter("@EncryptedAnswer",
SqlDbType.NVarChar)
objSqlParam.Value = EncryptString(CType(rptQA.Items(intCount -
1).Controls(1), TextBox).Text)
cmd.Parameters.Add(objSqlParam)
cmd.ExecuteNonQuery()
Next intCount

My problem is that
CType(rptQA.Items(intCount - 1).Controls(1), TextBox).Text
is always blank.

How do I refer to the data the user entered ? I am not able to
retrieve it !

Thanks a lot for spending the time reading this.
Alex.
 
S

Steve

I don't think that the Repeater supports data entry. You might look at the
DataList and DataGrid controls, or rethink your apporach using a form
instead of a table.

HTH,

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,233
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top