I have a repeater control and a check box on each row. On the checkbox click event I wanted to obtain the data items for this row. I have tried the following but the data items within Repeater Item is always empty.
protected void CheckChanged(object sender, EventArgs e)
{
string county = string.Empty;
string country = string.Empty;
string postcode = string.Empty;
string posttown = string.Empty;
var item = ((CheckBox) sender).Parent as RepeaterItem;
if (item != null)
{
if (item.ItemType == ListItemType.Item)
{
System.Data.DataRowView drv = (System.Data.DataRowView)(item.DataItem);
county = drv.Row["county"].ToString();
country = drv.Row["country"].ToString();
postcode = drv.Row["postcode"].ToString();
posttown = drv.Row["posttown"].ToString();
}
}
}
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<table border="1" width="100%" >
<tr>
<th>Select</th>
<th>Country</th>
<th>County</th>
<th>CSS Database Code</th>
<th>Postcode</th>
<th>Town</th>
</tr>
</HeaderTemplate>
<Itemtemplate>
<tr>
<td><asp:CheckBox ID="selectAddress" runat="server" OnCheckedChanged="CheckChanged" AutoPostBack="true"/></td>
<td><%# Eval("county")%>
<td><%# Eval("country")%></td>
<td><%# Eval("cssDatabaseCode")%></td>
<td><%# Eval("postcode")%><br /></td>
<td><%# Eval("postTown")%><br /></td>
</tr>
</Itemtemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
try this:
If
CheckBox
is InsideRepeater
ThenHere You can get the
RepeaterItem
by casting theCheckBox
'sNamingContainer
. Then you can useFindControl
to get the reference to your other Controls InsideRepeater