Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I am hving trouble using a textbox in a repeater. I am able to find the textbox in each repeater item but cannot access the Text attribute of the textbox or the label for that matter. My code is as follows. Any help would be greatly appreciated.

 

<script>

void SubmitAnswers(object o, EventArgs e)

{

TextBox answer;

Label answerNumber;

 

foreach(RepeaterItem ri in questionsRpt.Items)

{

if(ri.ItemType == ListItemType.Item || ri.ItemType == ListItemType.AlternatingItem)

{

answerNumber = (Label)ri.FindControl("answerNumber");

Response.Write(answerNumber.ID);

Response.Write(answerNumber.Text ); // no output here

answer = (TextBox)ri.FindControl("answer");

Response.Write(answer.ID);

Response.Write(answer.Text ); // no output here

}

}

}

</script>

 

<asp:repeater ID="questionsRpt" runat="server">

<headertemplate>

<table class="contenttext">

</headertemplate>

<itemtemplate>

<tr><td><asp:label ID="answerNumber" runat="server"><%# DataBinder.Eval(Container.DataItem, "number")%></asp:label>. </td><td><%# DataBinder.Eval(Container.DataItem, "question")%></td></tr>

<tr><td></td><td><asp:textbox runat="server" MaxLength="1000" ID="answer" /></td></tr>

</itemtemplate>

<footertemplate>

<tr><td></td><td align="right"><asp:button Text="Submit" runat="server" OnClick="SubmitAnswers" /></td></tr>

</table>

</footertemplate>

</asp:repeater>

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...