SORU
30 EKİM 2008, PERŞEMBE


Denetim sıralama: SortDirection her zaman Artan

Bir denetim var ve kullanıcı Başlığı tıkladığında unsurları sıralamak istiyorum.
Kendi veri kaynağı Listesinden bir nesne.

ASP bu şekilde tanımlanır :

<asp:GridView ID="grdHeader" AllowSorting="true" AllowPaging="false" 
    AutoGenerateColumns="false" Width="780" runat="server"  OnSorting="grdHeader_OnSorting" EnableViewState="true">
    <Columns>
        <asp:BoundField DataField="Entitycode" HeaderText="Entity" SortExpression="Entitycode" />
        <asp:BoundField DataField="Statusname" HeaderText="Status" SortExpression="Statusname" />
        <asp:BoundField DataField="Username" HeaderText="User" SortExpression="Username" />
    </Columns>
</asp:GridView>

Kod arkasında bu şekilde tanımlanır :
İlk yük :

protected void btnSearch_Click(object sender, EventArgs e)
{
    List<V_ReportPeriodStatusEntity> items = GetPeriodStatusesForScreenSelection();
    this.grdHeader.DataSource = items;
    this.grdHeader.DataBind();
}

kullanıcı başlıkları tıkladığında :

protected void grdHeader_OnSorting(object sender, GridViewSortEventArgs e)
{
    List<V_ReportPeriodStatusEntity> items = GetPeriodStatusesForScreenSelection();
    items.Sort(new Helpers.GenericComparer<V_ReportPeriodStatusEntity>(e.SortExpression, e.SortDirection));
    grdHeader.DataSource = items;
    grdHeader.DataBind();
}

Benim sorunum bu e.SortDirection her zaman Artan ayarlanır.
Benzer bir kod ile web sayfası ve iyi çalışıyor, e var.Artan ve Azalan SortDirection arasında geçiş yapar.

Ben yanlış ne yaptım ?

CEVAP
19 AĞUSTOS 2009, ÇARŞAMBA


Oturum ve görünüm durumu ile bu sorun da SortColumn ve Yön eğer sayfada birden fazla denetim ise orada saklanır denetim kontrol izlemek için.

Oturum ve görünüm durumu için alternatif bir Denetim için 2 öznitelikleri ekleyin ve Sütun ve Yönünü takip edin bu şekilde.

İşte bir örnek:

private void GridViewSortDirection(GridView g, GridViewSortEventArgs e, out SortDirection d, out string f)
{
    f = e.SortExpression;
    d = e.SortDirection;

    //Check if GridView control has required Attributes
    if (g.Attributes["CurrentSortField"] != null && g.Attributes["CurrentSortDir"] != null)
    {
        if (f == g.Attributes["CurrentSortField"])
        {
            d = SortDirection.Descending;
            if (g.Attributes["CurrentSortDir"] == "ASC")
            {
                d = SortDirection.Ascending;
            }
        }

        g.Attributes["CurrentSortField"] = f;
        g.Attributes["CurrentSortDir"] = (d == SortDirection.Ascending ? "DESC" : "ASC");
    }

}

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Living Waters

    Living Water

    9 AĞUSTOS 2006
  • NightShader1

    NightShader1

    25 Temmuz 2006
  • The Verge

    The Verge

    8 AĞUSTOS 2006