Repeater Issue

  • Thread starter Thread starter Mick Walker
  • Start date Start date
M

Mick Walker

I am using a repeater to display contacts to the user.

Here is my repeater:

<asp:Repeater ID="RepContacts" runat="server">

<HeaderTemplate><table cellpadding="5" cellspacing="2">
<tr>
<td><b>Contact Name</b></td>

<td></td>
<td><b>Invite</b></td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr class="RowStyle">
<td align="left" valign="top">
<asp:label width="300px" ID="lblName"
Text='<%# left(Eval("Name"), 280) %>' runat="server"></asp:label>
<asp:TextBox ID="txtID" runat="server"
Visible="false" Text='<%#Eval("ID") %>' />
<asp:TextBox ID="txtEmail"
runat="server" Visible="false" Text='<%#Eval("Email") %>' /></td>
<td>&nbsp;</td>
<td align="left" valign="top">
<asp:CheckBox ID="chkInvite"
runat="server" />
</td>
</tr>
</ItemTemplate>
<FooterTemplate></table></FooterTemplate>
</asp:Repeater>

I set the data source property via my code behind and bind it to the
repeater, and all works fine.

When i come to process the user options however, I have an issue. Here
is my code:

'loop through the repeater
For Each Item As RepeaterItem In RepContacts.Items
Dim chkInvite As New CheckBox
ChkInvite = CType(Item.FindControl("chkInvite"), CheckBox)
Dim txtEmail As New TextBox
txtEmail = CType(Item.FindControl("txtEmail"), TextBox)
Dim txtID As New TextBox
txtID = CType(Item.FindControl("txtID"), TextBox)
If chkInvite.Checked = True Then
'Do Stuff ' Never gets called for some reason???
End If

Next

When I debug, not matter what the value of the checkbox on the repeater,
the code picks it up as Checked = False. It gets the values of the text
boxes fine, but I am really at a loss as to why this is happening.


Anyone care to lend a hand?

Regards
Mick
 
Hi,

and in Page_Load you do databind inside If Not Page.IsPostBack check? You
shouldn't databind on every request, that's the point.
 
Teemu said:
Hi,

and in Page_Load you do databind inside If Not Page.IsPostBack check? You
shouldn't databind on every request, that's the point.
No the data is only being bound in the button event.
 
Normally only accidental rebinding causes the state of CheckBoxes etc to
appear as if selections has no impact (basically because databinding clears
the changes before postback events). So post some code that demonstrates
what happens on your page.
 
Teemu said:
Normally only accidental rebinding causes the state of CheckBoxes etc to
appear as if selections has no impact (basically because databinding clears
the changes before postback events). So post some code that demonstrates
what happens on your page.
I figured out my problem.

I was using a 3rd party AJAX control on the page, and the AutoPostback
event of the checkbox was set to true. Stupid error, but thanks for your
help.
 
Back
Top