У меня есть элемент управления повторителем, привязанный к общему List<>
.
Все элементы повторителей находятся в собственном теге <div>
, поэтому он дает хороший визуальный эффект блока, а также стандартный заполнитель для всех элементов.
С пользовательской сортировкой я смог упорядочить результаты по своему стандарту, но теперь мне нужно что-то нестандартное.
Мне нужно иметь возможность взять выбранный элемент в блоке <div>
и переместить его либо в нижнюю, либо в верхнюю часть списка элементов повторителей.
Есть ли способ сделать это? Либо привязкой, либо методом 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")
});
}
-Тот же метод- сортировка данных, затем привязка
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; }
}
Реальное применение моего вопроса Если есть «прикрепленное» совпадение, оно должно отображаться над совпадениями независимо от даты, статуса или имени.