【问题标题】:Change the gridview sort image at runtime在运行时更改 gridview 排序图像
【发布时间】:2011-07-30 12:44:17
【问题描述】:

我希望在特定列的排序完成后在运行时更改 gridview 排序图像,以便用户可以识别排序完成的列和方向。

假设有 10 列,客户 ID、名称等。我对客户名称进行了降序排序,然后降序排序的图像应更改为其他图像,以便于识别。

这怎么可能?

【问题讨论】:

标签: .net asp.net visual-studio sorting gridview


【解决方案1】:

以下是我会怎么做,这是一个有效的解决方案,它有效:

 OnRowCreated="gvInActive_RowCreated" 

protected void gvInActive_RowCreated(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
        {
            if (!(e.Row == null) && e.Row.RowType == DataControlRowType.Header)
            {
                #region sorting
                foreach (TableCell cell in e.Row.Cells)
                {
                    if (cell.HasControls())
                    {
                        if (cell.Controls[0].ToString() != "System.Web.UI.LiteralControl")
                        {
                            LinkButton button = (LinkButton)cell.Controls[0];
                            if (!(button == null))
                            {
                                System.Web.UI.WebControls.Image image = new System.Web.UI.WebControls.Image();
                                //image.ImageUrl = "images/nosort.gif";
                                image.Visible = false;
                                if (this.gvInactive.SortExpression == button.CommandArgument)
                                {
                                    if (gvInactive.SortDirection == System.Web.UI.WebControls.SortDirection.Ascending)
                                    {
                                        image.Visible = true;
                                        image.ImageUrl = "../../images/sort_asc.gif";
                                    }
                                    else
                                    {
                                        image.Visible = true;
                                        image.ImageUrl = "../../images/sort_desc.gif";
                                    }
                                }
                                //else
                                //{
                                //    image.Visible = true;
                                //    image.ImageUrl = "images/sort_none.gif";
                                //}
                                cell.Controls.Add(image);
                            }
                        }
                    }
                }
                #endregion
            }
        } 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-22
    • 1970-01-01
    • 2018-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多