gpt4 book ai didi

C# Gridview 标题样式不适用于排序

转载 作者:行者123 更新时间:2023-11-28 02:57:01 25 4
gpt4 key购买 nike

我不明白为什么 SortedDescendingHeaderStyle-CssClassSortedAscendingHeaderStyle-CssClass 在排序我的 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>

最佳答案

感谢 ConnorsFan,我得以解决这个问题。基本上遍历列并匹配请求的排序表达式以获得列的索引。这是我的解决方案

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

关于C# Gridview 标题样式不适用于排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36597110/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com