我有一箇中繼器控制綁定到通用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")
});
}
-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; }
}
現實世界,我的問題的應用 如果有一個「stickied」比賽 - 它必須出現在比賽的頂部,無論日期,狀態或名稱
添加代碼..希望這會有所幫助 – TheGeekZn
很抱歉,對於很長的響應時間..從未見過更新。我可以看到這個代碼的過程..將盡快嘗試。 – TheGeekZn