更改gridview中的排序图像按钮 [英] Change sorting image button in gridview

查看:135
本文介绍了更改gridview中的排序图像按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  <asp:ImageButton ID="lnkEmpIdUp" runat="server" ImageUrl="~/Images/upArrow.png" CommandName="EMP_ID_NO" OnClick="lnkSorting_Click" />
 &nbsp;
 <asp:ImageButton ID="lnkEmpIdDown" runat="server" ImageUrl="~/Images/downArrow.png" CommandName="EMP_ID_NO" OnClick="lnkSorting_Click" />

如上面的代码所示,有2个图像按钮(保留在Gridview头文件模板中)将执行排序。仔细看,两个控件的命令名和onClick事件都是相同的。

As the above code says, there are 2 images button (Kept in Gridview header template) which clicked, would perform sorting. Close look would result that both the controls have same command name and same onClick Event.

OnClick事件处理通过命令名排序的列,并且处理排序方向通过隐藏的领域。见下面的代码

The OnClick Event handles the column to be sorted through command name and the sorting direction is handled through hidden field. See below code

    protected void lnkSorting_Click(object sender, EventArgs e)
            {
                // Initialize variables
                //Get Dataset values here for the grid.
                var imgSort = sender as ImageButton;
                string colName = imgSort.CommandName;

                if (imgSort.ImageUrl.Trim().ToUpper().Contains(("up").ToUpper())) // If Up(Ascending)arrow is clicked.
                {
                    if (hdnSortDir.Value.Equals(string.Empty) || hdnSortDir.Value.ToString().Equals("desc"))
                    {
                        hdnSortDir.Value = "asc";
                        //imgSort.ImageUrl = "~/Images/ascending.gif";
                    }
                }
                else if (imgSort.ImageUrl.Trim().ToUpper().Contains(("down").ToUpper()))
                {
                    hdnSortDir.Value = "desc";
                }

.....Sorting Logic...

}

我的疑问:在gridview中执行排序时,如何在运行时更改图像?在对列员工姓名进行升序排序后,说这个列的升序图像应该改变为其他图像,以便用户能够识别哪一列是排序和朝哪个方向。

My Doubt: How can i change the image at run time when the sorting is performed in gridview? Say after sorting the column "Employee Name" ascending, the ascending image for that column should change to some other image so that user could identify as to which column is sort and in which direction.

Please help !!!

Please help!!!

谢谢!

Thanks!

推荐答案

通过在隐藏字段中设置排序表达式和排序方向值,可以在rowdatabound中完成相同的操作。

The same can be done in rowdatabound by setting the sort expression and sort direction values in hidden field.

这篇关于更改gridview中的排序图像按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆