2016-04-13 38 views
2

我無法弄清楚爲什麼SortedDescendingHeaderStyle-CssClassSortedAscendingHeaderStyle-CssClass正在應用到排序我的GridView標題?C#Gridview標題樣式不適用於排序

這是我的標記。我需要在代碼後面配置它嗎?

.ascending a 
    { 
     background: url(/images/asc.gif) right no-repeat; 
     display: block; 
     padding: 0 25px 0 5px; 
    } 

    .descending a 
    { 
     background: url(/images/desc.gif) right no-repeat; 
     display: block; 
     padding: 0 25px 0 5px; 
    } 

<asp:GridView ID="gvOrderItems" runat="server" GridLines="None" CellSpacing="-1" AutoGenerateColumns="false" SortedAscendingHeaderStyle-CssClass="ascending" 
    AllowSorting="true" OnRowDataBound="gvOrderItems_RowDataBound" SortedDescendingHeaderStyle-CssClass="descending" OnSorting="gvOrderItems_Sorting" EnableViewState="true" AllowPaging="true" PageSize="10" OnPageIndexChanging="gvOrderItems_PageIndexChanging1">      
    <Columns>        
    <asp:BoundField DataField="OrderDate" HeaderText="Date" HeaderStyle-Font-Underline="true" HeaderStyle-ForeColor="White" ControlStyle-Font-Underline="true" DataFormatString="{0:dd/MM/yyyy}" SortExpression="OrderDate" /> 
    <asp:BoundField DataField="OrderNumber" HeaderText="Order Number" HeaderStyle-Font-Underline="true" HeaderStyle-ForeColor="White" SortExpression="OrderNumber" /> 
    <asp:BoundField DataField="SKUNumber" HeaderText="Product Number" HeaderStyle-Font-Underline="true" HeaderStyle-ForeColor="White" SortExpression="SKUNumber" /> 
    <asp:BoundField DataField="OrderItemSKUName" HeaderText="Product Description" /> 
    <asp:BoundField DataField="mtrx_Code2" HeaderText="Size" /> 
    <asp:BoundField DataField="OrderItemUnitCount" HeaderText="OTY" /> 
    <asp:BoundField DataField="OrderItemStatus" HeaderText="Status" />   
    </Columns> 
    <PagerStyle HorizontalAlign="Right" CssClass="cssPager"/>  

</asp:GridView> 
+0

您是否嘗試對數據進行排序並檢查類是否被應用? –

+0

您的GridView可能必須綁定到標記中的數據源才能自動工作。 – ConnorsFan

+0

嗨Piyush類從來沒有得到應用時,我排序的數據?無論如何,我可以在排序事件中通過代碼添加它? – Kevin

回答

0

感謝ConnorsFan我能解決這個問題。基本上遍歷列並匹配請求的排序表達式以獲得列的索引。這是我的解決方案

foreach (DataControlField col in gvOrderItems.Columns) 
{ 
    if (col.SortExpression == sortExpression) 
    { 
     int index = gvOrderItems.Columns.IndexOf(col); 
     gvOrderItems.Columns[index].HeaderStyle.CssClass = "descending"; 
    } 
}