【问题标题】:Gridview SortExpression is emptyGridview SortExpression 为空
【发布时间】:2011-07-25 12:55:06
【问题描述】:

下面的代码显示了在对 GridView 进行排序但 GridView SortExpression 返回 NULL 时添加升序降序图像。

知道为什么会这样吗?

 protected void grvSample_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header)
        {
            foreach (TableCell tc in e.Row.Cells)
            {
                if (tc.HasControls())
                {
                    LinkButton lnk = (LinkButton)tc.Controls[0];
                    if (lnk != null)
                    {
                        System.Web.UI.WebControls.Image img = new System.Web.UI.WebControls.Image();
                        img.ImageUrl = "~/Images/" + (grvSample.SortDirection == SortDirection.Ascending ? "asc" : "desc") + ".gif";
                        if (grvSample.SortExpression == lnk.CommandArgument)
                        {
                            // adding a space and the image to the header link
                            tc.Controls.Add(new LiteralControl(" "));
                            tc.Controls.Add(img);
                        }
                    }
                }
            }
        }
    }

【问题讨论】:

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


    【解决方案1】:

    我认为在创建行时不会设置它。单击排序列时设置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多