Hello i have a repeater that will present data as a table with checkbox for each row, so i want to show the checked rows data when a button is clicked.
.aspx code:
<asp:Repeater ID="rptItems" runat="server">
<HeaderTemplate>
<table class="table table-bordered table-hover table-responsive table-striped table-condensed">
<tr>
<th> </th>
<th>Goods Desc</th>
<th>Balance Units</th>
<th>Exit Units</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><asp:CheckBox ID="cbItem" runat="server" /></td>
<td><%#Eval("ItemDesc") %></td>
<td><%#Eval("InvoicBalanceUnits") %></td>
<td><asp:TextBox ID="txtExitUnits" runat="server" ></asp:TextBox>
<asp:RegularExpressionValidator ID="revUnits" runat="server" Display="Dynamic" ControlToValidate="txtExitUnits" ValidationExpression="^\d+$" ErrorMessage="Please, insert a number." CssClass="text-danger"></asp:RegularExpressionValidator>
<asp:RequiredFieldValidator ID="rfvUnits" runat="server" Display="Dynamic" ControlToValidate="txtExitUnits" ErrorMessage="Insert number of units." CssClass="text-danger"></asp:RequiredFieldValidator>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
the code behind:
protected void btnExit_Click(object sender, EventArgs e)
{
List<RepeaterItem> selectedItems = rptItems.Items.Cast<RepeaterItem>().Where(x => ((CheckBox)x.FindControl("cbItem")).Checked).ToList();
Repeater1.DataSource = selectedItems;
Repeater1.DataBind();
}
Repeater1 will contain the data selected through :selectedItems
this is the repeater1
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<table class="table table-bordered table-hover table-responsive table-striped table-condensed">
<tr>
<th>Goods Desc</th>
<th>Balance Units</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%#Eval("ItemDesc") %></td>
<td><%#Eval("InvoicBalanceUnits") %></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
when i run the code it gives me an error that "ItemDesc" isn't exist in repeater1, whats wrong ?
Solved by reference to this: