第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

GridView排序:SortDirection始終升序

GridView排序:SortDirection始終升序

回首憶惘然 2019-10-18 14:29:38
我有一個(gè)gridview,當(dāng)用戶(hù)單擊標(biāo)題時(shí),我需要對(duì)其元素進(jìn)行排序。它的數(shù)據(jù)源是一個(gè)List對(duì)象。aspx是這樣定義的:<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>后面的代碼是這樣定義的:第一次加載:protected void btnSearch_Click(object sender, EventArgs e){    List<V_ReportPeriodStatusEntity> items = GetPeriodStatusesForScreenSelection();    this.grdHeader.DataSource = items;    this.grdHeader.DataBind();}當(dāng)用戶(hù)點(diǎn)擊標(biāo)題時(shí):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();}我的問(wèn)題是e.SortDirection始終設(shè)置為升序。我的網(wǎng)頁(yè)使用了類(lèi)似的代碼,并且運(yùn)行良好,e.SortDirection在升序和降序之間交替。我做錯(cuò)了什么 ?
查看完整描述

3 回答

?
小唯快跑啊

TA貢獻(xiàn)1863條經(jīng)驗(yàn) 獲得超2個(gè)贊

您可以使用會(huì)話(huà)變量來(lái)存儲(chǔ)最新的排序表達(dá)式,并在下次對(duì)網(wǎng)格進(jìn)行排序時(shí),將網(wǎng)格的排序表達(dá)式與存儲(chǔ)最后一個(gè)排序表達(dá)式的Session變量進(jìn)行比較。如果兩列相等,則檢查上一個(gè)排序的方向,然后按相反的方向排序。


例:


DataTable sourceTable = GridAttendence.DataSource as DataTable;

DataView view = new DataView(sourceTable);

string[] sortData = ViewState["sortExpression"].ToString().Trim().Split(' ');

if (e.SortExpression == sortData[0])

{

    if (sortData[1] == "ASC")

    {

        view.Sort = e.SortExpression + " " + "DESC";

        this.ViewState["sortExpression"] = e.SortExpression + " " + "DESC";

    }

    else

    {

        view.Sort = e.SortExpression + " " + "ASC";

        this.ViewState["sortExpression"] = e.SortExpression + " " + "ASC";

    }

}

else

{

    view.Sort = e.SortExpression + " " + "ASC";

    this.ViewState["sortExpression"] = e.SortExpression + " " + "ASC";

}


查看完整回答
反對(duì) 回復(fù) 2019-10-18
  • 3 回答
  • 0 關(guān)注
  • 962 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)