中继器控制:移动个人项目



我有一个中继器控件绑定到通用List<>

中继器的项目都有其自己的<div>标签,因此具有良好的块视觉效果,以及所有项目的标准占位符。

通过自定义排序,我能够在其自己的标准中安排结果,但是现在我需要一些不是标准的东西。

我需要能够在 <div>块中选择选定的项目,然后将其移至中继器项目列表的底部或顶部。

有什么办法可以做到这一点?通过绑定,或使用RepeAter的repeater_ItemDataBound()方法?

代码很长..所以我将发布我认为"需要知道"的内容。

填充通用列表

                        while (rdr.Read())
                        {
                            challenge.Add(new ChallengeList
                                {
                                    GameName = rdr["gameName"].ToString(),
                                    CreatorName = rdr["creatorName"].ToString(),
                                    MediatorName = rdr["mediatorName"].ToString(),
                                    ChallengeID = rdr["challengeId"].ToString(),
                                    ChallengeAccepted = rdr["accepted"].ToString(),
                                    MatchDate = DateTime.Parse(rdr["matchDate"].ToString()).ToString("dd MMMM yyyy hh:mm")
                                });
                        }

-same方法 - 对数据进行排序,然后绑定

    switch (sort)
    {
        case "name":
            Comparison<ChallengeList> name = ChallengeList.CompareGameName;
            challenge.Sort(name);
            break;
        case "date":
            Comparison<ChallengeList> date = ChallengeList.CompareDate;
            challenge.Sort(date);
            break;
        case "status":
            Comparison<ChallengeList> status = ChallengeList.CompareStatus;
            challenge.Sort(status);
            break;
    }
    rptChallenges.DataSource = challenge;
    rptChallenges.DataBind();

通用列表类(带排序)

/// <summary>
/// Class ChallengeList
/// With sorting
/// </summary>
public class ChallengeList
{
    /// <summary>
    /// Compares the name of the game.
    /// </summary>
    /// <param name="game1">The game1.</param>
    /// <param name="game2">The game2.</param>
    /// <returns>System.Int32.</returns>
    public static int CompareGameName(ChallengeList game1, ChallengeList game2)
    {
        return String.Compare(game1.GameName, game2.GameName, StringComparison.Ordinal);
    }
    /// <summary>
    /// Compares the status.
    /// </summary>
    /// <param name="status1">The status1.</param>
    /// <param name="status2">The status2.</param>
    /// <returns>System.Int32.</returns>
    public static int CompareStatus(ChallengeList status1, ChallengeList status2)
    {
        return string.Compare(status1.ChallengeAccepted, status2.ChallengeAccepted, StringComparison.Ordinal);
    }
    /// <summary>
    /// Compares the date.
    /// </summary>
    /// <param name="date1">The date1.</param>
    /// <param name="date2">The date2.</param>
    /// <returns>System.Int32.</returns>
    public static int CompareDate(ChallengeList date1, ChallengeList date2)
    {
        return string.Compare(date1.MatchDate, date2.MatchDate, StringComparison.Ordinal);
    }
    /// <summary>
    /// Compares the date reverse.
    /// </summary>
    /// <param name="date2">The date2.</param>
    /// <param name="date1">The date1.</param>
    /// <returns>System.Int32.</returns>
    public static int CompareDateReverse(ChallengeList date2, ChallengeList date1)
    {
        return string.Compare(date1.MatchDate, date2.MatchDate, StringComparison.Ordinal);
    }
    /// <summary>
    /// Gets or sets the name of the game.
    /// </summary>
    /// <value>The name of the game.</value>
    public string GameName { get; set; }
    /// <summary>
    /// Gets or sets the name of the creator.
    /// </summary>
    /// <value>The name of the creator.</value>
    public string CreatorName { get; set; }
    /// <summary>
    /// Gets or sets the name of the mediator.
    /// </summary>
    /// <value>The name of the mediator.</value>
    public string MediatorName { get; set; }
    /// <summary>
    /// Gets or sets the challenge ID.
    /// </summary>
    /// <value>The challenge ID.</value>
    public string ChallengeID { get; set; }
    /// <summary>
    /// Gets or sets the challenge accepted.
    /// </summary>
    /// <value>The challenge accepted.</value>
    public string ChallengeAccepted { get; set; }
    /// <summary>
    /// Gets or sets the match date.
    /// </summary>
    /// <value>The match date.</value>
    public string MatchDate { get; set; }
}

我的问题的真实应用如果有"粘性"匹配 - 无论日期,状态或名称

,它都必须出现在比赛的顶部。

我建议您在看到中继器之前订购列表中的数据。如果不可能给定数据的结构和/或中继器的项目模板,请您提供数据的样本和中继器,以便我们进一步帮助?

编辑Asker发布代码

而不是将挑战设定为中继器的数据源,您应该将所有需要在列表顶部的项目分为新列表中,然后将其他其他项目附加到顶级项目的末尾。<<<<<<<<<<<<

类似的东西:

var topItmes = new List<ChallengeList>();
var otherItmes = new List<ChallengeList>();
foreach (var item in challenge)
{
    if(/*item needs to be on top*/)
    {
        topItmes.Add(item);
    }
    else
    {
        otherItmes.Add(item);
    }
}
topItmes.AddRange(otherItmes);

取决于一个项目在顶部的标准,您可以使用Linq表达式来简化此代码。

最新更新