2

我使用教程使用中继器在我的项目页面上显示名称列表。

所以我正在使用动态数据,在我的 aspx.cs 页面中我有:

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();

在我的 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>

错误来自OnItemDataBound="subContractors_ItemDataBound".

我将其链接到什么或在哪里?我目前没有subContractors_ItemDataBound

4

2 回答 2

7

只需OnItemDataBound="subContractors_ItemDataBound"从您的 aspx 页面中删除

编辑发生此错误是因为您 subContractors_ItemDataBound在 .cs 文件中没有处理OnItemDataBound事件的方法,因此您必须处理OnItemDataBound事件或仅删除OnItemDataBound="subContractors_ItemDataBound"

编辑以绑定字符串列表使用:

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

于 2013-01-30T13:33:25.383 回答
2

在您的页面加载(或您想要加载数据的任何地方)执行此操作以将您的数据与转发器链接

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

并删除

    OnItemDataBound="subContractors_ItemDataBound"
于 2013-01-30T13:34:43.007 回答