การควบคุมทวนสัญญาณ : ย้ายแต่ละรายการ

ฉันมีการควบคุมรีพีทเตอร์ที่เชื่อมโยงกับ 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; }
}

การประยุกต์ใช้คำถามของฉันในโลกแห่งความเป็นจริง หากมีการจับคู่ที่ 'ติดหนึบ' - จะต้องปรากฏที่ด้านบนของการจับคู่โดยไม่คำนึงถึงวันที่ สถานะ หรือชื่อ


person TheGeekZn    schedule 25.10.2012    source แหล่งที่มา


คำตอบ (1)


ฉันขอแนะนำให้คุณเรียงลำดับข้อมูลในรายการของคุณก่อนที่คุณจะเห็นเหมือนกันกับทวนสัญญาณ หากเป็นไปไม่ได้เนื่องจากโครงสร้างข้อมูลของคุณและ/หรือเทมเพลตรายการของทวนสัญญาณ คุณช่วยกรุณารวมตัวอย่างข้อมูลและทวนสัญญาณด้วย เพื่อที่เราจะได้ช่วยเหลือเพิ่มเติมได้หรือไม่

แก้ไขหลังจากที่ผู้ถามโพสต์โค้ด

แทนที่จะตั้ง Challenge เป็นแหล่งข้อมูลสำหรับ Repeater คุณควรแยกรายการทั้งหมดที่ต้องอยู่ด้านบนของรายการออกเป็นรายการใหม่ จากนั้นจึงเพิ่มรายการอื่นๆ ต่อท้ายรายการบนสุด

บางอย่างเช่นนี้:

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 เพื่อทำให้โค้ดนี้ง่ายขึ้น

person Fisch    schedule 25.10.2012
comment
ขออภัยสำหรับการตอบกลับที่ยาวนาน .. ไม่เคยเห็นการอัปเดต ฉันสามารถเห็นกระบวนการของรหัสนี้ .. จะพยายามโดยเร็วที่สุด - person TheGeekZn; 25.10.2012