ASP:中继器不工作

时间:2013-01-30 13:30:59

标签: asp.net asprepeater

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

所以我正在使用动态数据,在我的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

2 个答案:

答案 0 :(得分:7)

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

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

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

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

答案 1 :(得分:2)

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

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

并删除

    OnItemDataBound="subContractors_ItemDataBound"