【问题标题】:ASP: Repeater not workingASP:中继器不工作
【发布时间】:2013-01-30 13:30:59
【问题描述】:

我使用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

【问题讨论】:

    标签: asp.net asprepeater


    【解决方案1】:

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

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

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

    &lt;asp:Label ID="SubCon" Text='&lt;%# Container.DataItem %&gt;' runat="server"&gt;&lt;/asp:Label&gt;

    【讨论】:

    • 感谢您的回复,我删除了 OnItemDataBound="subContractors_ItemDataBound 但仍然没有乐趣
    • @John 尝试添加 repeaterShowSubContractorName.DataSource =subContractors; repeaterShowSubContractorName.DataBind();
    • 中继器有返回数据吗?
    • @MahmoudFarahat 是的,谢谢我需要数据绑定,但现在我在尝试绑定字符串列表时遇到错误: 返回错误:DataBinding: 'System.String' 不包含名为 'subContractors' 的属性。
    • @RyanMcDonough 表中有数据,但不允许我绑定字符串
    【解决方案2】:

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

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

    并删除

        OnItemDataBound="subContractors_ItemDataBound"
    

    【讨论】:

    • 设置源后需要repeaterShowSubContractorName.DataBind()。我已经更新了我的答案。另外,subContractors中是否有数据
    • 是的,谢谢我需要数据绑定,但现在我在尝试绑定字符串列表时遇到错误: 返回错误:DataBinding: 'System.String' 不包含名为 'subContractors' 的属性。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-03
    相关资源
    最近更新 更多