如何在分页时在网格视图中维护标题复选框(全选)列 [英] how to maintain header checkbox (Select All) column in gridviews while paging

查看:69
本文介绍了如何在分页时在网格视图中维护标题复选框(全选)列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HIii ..我的gridview唯一的问题是它根本没有保持标题复选框状态..



这是我的问题



选中顶部的复选框以选择所有记录

转到第二页

再次回到第一页顶部

顶部的选中复选框未选中,但其他复选框仍未选中







这是我的代码



HIii.. the only problem with my gridview is its not at all maintaining the header check box status..

This is my issue

Check Checkbox at the top to select all records
Go to second page
Again come back to first page top
Selected checkbox at the top is unchecked but other checkboxes are still checked



This is my code

protected void grdEmployee_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            try
            {
                grdEmployee.PageIndex = e.NewPageIndex;
 
                List<string> listEmpId = new List<string>();
                if (hdnAdvanceSearch.Value == "Normal")
                {
                    if (ViewState["empListNormal"] != null)
                    {
                        listEmpId = (List<string>)ViewState["empListNormal"];
                    }
                    foreach (GridViewRow row in grdEmployee.Rows)
                    {
                        CheckBox chkRow = (CheckBox)row.FindControl("chkRow");
                        CheckBox chkHeader = (CheckBox)row.FindControl("chkHeader");
                        HiddenField hdnEmployeeID = (HiddenField)row.FindControl("hdnEmployeeID");
                        
                        if (chkRow.Checked)
                        {
                            if (!listEmpId.Contains(hdnEmployeeID.Value))
                            {
                                listEmpId.Add(hdnEmployeeID.Value);
                            }
                        }
                        else
                        {
                            if (listEmpId.Contains(hdnEmployeeID.Value))
                            {
                                listEmpId.Remove(hdnEmployeeID.Value);
                            }
                        }
                    }
                    ViewState["empListNormal"] = listEmpId;
                    BindEmployeeGrid();
                }
                else if (hdnAdvanceSearch.Value == "Advanced")
                {
                    if (ViewState["empListAdvanced"] != null)
                    {
                        listEmpId = (List<string>)ViewState["empListAdvanced"];
                    }
                    foreach (GridViewRow row in grdEmployee.Rows)
                    {
                        CheckBox chkRow = (CheckBox)row.FindControl("chkRow");
                        HiddenField hdnEmployeeID = (HiddenField)row.FindControl("hdnEmployeeID");
                        if (chkRow.Checked)
                        {
                            if (!listEmpId.Contains(hdnEmployeeID.Value))
                            {
                                listEmpId.Add(hdnEmployeeID.Value);
                            }
                        }
                        else
                        {
                            if (listEmpId.Contains(hdnEmployeeID.Value))
                            {
                                listEmpId.Remove(hdnEmployeeID.Value);
                            }
                        }
                    }
                    ViewState["empListAdvanced"] = listEmpId;
                    BindAdvancedEmployeeGrid();
                }
            }
            catch (Exception ex)
            { 
               
            }
        }

推荐答案

尝试过网格控制...... :)





http://www.obout.com/grid/aspnet_columns_types_select.aspx [ ^ ]
Try obout grid control...:)


http://www.obout.com/grid/aspnet_columns_types_select.aspx[^]


这篇关于如何在分页时在网格视图中维护标题复选框(全选)列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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