I’ve used this tutorial to use a repeater to display a list of names on a page on my project.
So I’m using dynamic data and in my aspx.cs page I have:
List<string> subContractors = new List<string>();
Context db = new Context();
subContractors = (from SUBContractors in db.BOQ_SubContractors
where SUBContractors.Bill_Of_Quantity_id == this.boqId
select SUBContractors.Sub_Contractor.Company_Name).ToList();
repeaterShowSubContractorName.DataSource = subContractors;
repeaterShowSubContractorName.DataBind();
In my aspx:
<asp:Repeater ID="repeaterShowSubContractorName" runat="server" OnItemDataBound="subContractors_ItemDataBound">
<HeaderTemplate>
<table>
<tr>
<th>
<asp:Label ID="SubConName" Text="SubContractor Name" runat="server"></asp:Label>
</th>
</tr>
</table>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:Label ID="SubCon" Text='<%# Eval("subContractors") %>' runat="server"></asp:Label>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
The error is coming from OnItemDataBound="subContractors_ItemDataBound".
What or where do I link this to? I have no subContractors_ItemDataBound at the moment.
just remove
OnItemDataBound="subContractors_ItemDataBound"from your aspx pageEdit this error occurred because you don’t have
subContractors_ItemDataBoundmethod in .cs file to handleOnItemDataBoundevent , so you have to handleOnItemDataBoundevent or just removeOnItemDataBound="subContractors_ItemDataBound"Edit to bind list of strings use :
<asp:Label ID="SubCon" Text='<%# Container.DataItem %>' runat="server"></asp:Label>