0

フロントエンド

<asp:Repeater ID="rpt_comments" runat="server" DataSourceID="sqldata_rpt_comments" OnLoad="rpt_comments_Load">
  <ItemTemplate>
    <div class="comments">
      <div class="news-comment-left">
          <asp:Image ID="imgCommentAvatar" Width="50px" Height="50px" runat="server" />
      </div>
      <div class="news-comment-right">
          <asp:Label ID="lblCommentProfile" runat="server"></asp:Label>
          <asp:Label ID="lblCommentAuthor" runat="server" Text='<%#Eval ("CommentsAuthor") %>' Visible="false"></asp:Label>
          <div style="float: right;"><%#Eval ("CommentsDate", "{0:dd.MM.yyyy}") %></div>
          <br />
          <%#Eval ("Comment") %><br />
      </div>
      <br />
      <br />
      <br />
      <br />
    </div>
  </ItemTemplate>
</asp:Repeater>

バックエンド

public void commentsprofiles()
{
    Label CommentAuthor = (Label)Tools.FindControlRecursive(rpt_comments, "lblCommentAuthor");
    Label CommentProfile = (Label)Tools.FindControlRecursive(rpt_comments, "lblCommentProfile");
    Image imgCommentAvatar = (Image)Tools.FindControlRecursive(rpt_comments, "imgCommentAvatar");

    ProfileCommon userProfile = Profile.GetProfile(CommentAuthor.Text);

    imgCommentAvatar.ImageUrl = userProfile.Avatar;
    CommentProfile.Text = userProfile.NickName;
}
protected void rpt_comments_Load(object sender, EventArgs e)
{
    commentsprofiles();
}

ご覧のとおり、リピーターでコントロールを取得しようとしています。コントロールをFindControlRecursive抽出し、その内容を伝えたい場合は、asp.net メンバーシップでプロファイルを取得します。これも機能しますが、1 に対してのみですリピーターでアイテムを繰り返しているので、CommentAuthorそこにあるそれぞれのプロファイルを繰り返し続けるようにコーディングする方法の助けが必要です。

4

1 に答える 1

1

Repeater.ItemDataBoundイベントを使用する

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeater.itemdatabound.aspx

于 2012-10-26T14:45:17.013 に答える