Question

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.

Was it helpful?

Solution

just remove OnItemDataBound="subContractors_ItemDataBound" from your aspx page

Edit this error occurred because you don't have subContractors_ItemDataBound method in .cs file to handle OnItemDataBound event , so you have to handle OnItemDataBound event or just remove OnItemDataBound="subContractors_ItemDataBound"

Edit to bind list of strings use :

<asp:Label ID="SubCon" Text='<%# Container.DataItem %>' runat="server"></asp:Label>

OTHER TIPS

Do this on your page load (or wherever you want to laod data) to link your data with repeater

    repeaterShowSubContractorName.DataSource = subContractors;
    repeaterShowSubContractorName.DataBind();

and remove

    OnItemDataBound="subContractors_ItemDataBound"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top