【问题标题】:Grid View Sorting Arrows not getting displayed网格视图排序箭头未显示
【发布时间】:2016-12-31 05:04:02
【问题描述】:

我正在对网格视图进行排序。排序工作完美。现在我正在尝试在每个标题列旁边添加排序箭头。我几乎尝试了所有方法,但箭头没有显示在我的 UI.PFB 中代码:

CSS:

th .ascending a {
    background: url(images/ascArrow.gif) no-repeat;
    display: block;
    padding: 0 4px 0 15px;
}

th .descending a {
    background: url(images/descArrow.gif) no-repeat;
    display: block;
    padding: 0 4px 0 15px;
}

代码背后:

protected void RPMData_Sorting(object sender, GridViewSortEventArgs e)
    {
        if (TextData.Text == String.Empty)
        {
            SqlCommand cmd = new SqlCommand("select Customer_Name,Site_Type,Source,Destination,Latency,Jitter_Priority_Real_Time,Jitter_Real_Time,PacketLoss_Priority_Real_Time,PacketLoss_Real_Time,PacketLoss_Other_Classes from RPM", con);
            con.Open();
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(dt1);
            con.Close();
            if (dt1.Rows.Count > 0)
            {
                string sortingDirection = string.Empty;
                if (direction == SortDirection.Ascending)
                {
                    direction = SortDirection.Descending;
                    RPMData.HeaderStyle.CssClass = "descending";
                    sortingDirection = "Desc";
                }
                else
                {
                    direction = SortDirection.Ascending;
                    RPMData.HeaderStyle.CssClass = "ascending";
                    sortingDirection = "Asc";
                }

                DataView sortedView = new DataView(dt1);
                sortedView.Sort = e.SortExpression + " " + sortingDirection;
                Session["SortedView"] = sortedView;
                RPMData.DataSource = sortedView;
                RPMData.DataBind();
            }
        }

//排序逻辑根据应用的过滤器有2个条件。我这里只添加了第一个条件

GridView 标签:

<asp:GridView CssClass="infoTable" ID="RPMData" runat="server" OnSelectedIndexChanged="Button1_Click" AllowPaging="True" PageSize="10" OnPageIndexChanging="RPMData_PageIndexChanging" AllowSorting="True" OnSorting="RPMData_Sorting" AutoGenerateColumns="False" SortedAscendingHeaderStyle-CssClass="ascending" SortedDescendingHeaderStyle-CssClass="descending">
    <HeaderStyle CssClass="ascending" />
        <Columns>

请帮帮我。

【问题讨论】:

    标签: c# css asp.net sorting


    【解决方案1】:

    HeaderStyle.CssClass 应用于整个标题行&lt;tr class="ascending"&gt;,而不是单独的th 单元格。将您的 CSS 更改为

    <style>
        .ascending a {
            background:url(images/ascArrow.gif) no-repeat;
            display: block;
            padding: 0 4px 0 15px;
        }
    
        .descending a {
            background:url(images/descArrow.gif) no-repeat;
            display: block;
            padding: 0 4px 0 15px;
        }
    </style>
    

    或者,如果您在其他地方使用该类,.ascending th a 将确保它只影响标题行。

    【讨论】:

      猜你喜欢
      • 2021-04-12
      • 1970-01-01
      • 2023-03-31
      • 1970-01-01
      • 2011-02-10
      • 2015-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多