protected void GvGrampacyatBin_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GvGrampacyatBin.PageIndex = e.NewPageIndex;

        DataTable dt = (DataTable)Session["dtBinFilter"];

        GvGrampacyatBin.DataSource = dt;
        GvGrampacyatBin.DataBind();
        AllPageCode();
        string temp = string.Empty;


        for (int i = 0; i < GvGrampacyatBin.Rows.Count; i++)
        {
            Label    lblconid = (Label)GvGrampacyatBin.Rows[i].FindControl("lblGrampacyatId");
            string[] split    = lblSelectedRecord.Text.Split(',');

            for (int j = 0; j < lblSelectedRecord.Text.Split(',').Length; j++)
            {
                if (lblSelectedRecord.Text.Split(',')[j] != "")
                {
                    if (lblconid.Text.Trim().ToString() == lblSelectedRecord.Text.Split(',')[j].Trim().ToString())
                    {
                        ((CheckBox)GvGrampacyatBin.Rows[i].FindControl("chkgvSelect")).Checked = true;
                    }
                }
            }
        }
    }
    protected void GvGrampacyatBin_OnSorting(object sender, GridViewSortEventArgs e)
    {
        HDFSortbin.Value = HDFSortbin.Value == "ASC" ? "DESC" : "ASC";
        DataTable dt = new DataTable();

        dt = objDesg.GetGrampacyatMasterInactive(Session["CompId"].ToString().ToString());
        DataView dv    = new DataView(dt);
        string   Query = "" + e.SortExpression + " " + HDFSortbin.Value + "";

        dv.Sort = Query;
        dt      = dv.ToTable();
        Session["dtBinFilter"]     = dt;
        GvGrampacyatBin.DataSource = dt;
        GvGrampacyatBin.DataBind();
        AllPageCode();
        lblSelectedRecord.Text = "";
    }
    protected void ImgbtnSelectAll_Click(object sender, ImageClickEventArgs e)
    {
        DataTable dtGrampacyat = (DataTable)Session["dtbinFilter"];

        if (ViewState["Select"] == null)
        {
            ViewState["Select"] = 1;
            foreach (DataRow dr in dtGrampacyat.Rows)
            {
                if (!lblSelectedRecord.Text.Split(',').Contains(dr["Grampacyat_ID"]))
                {
                    lblSelectedRecord.Text += dr["Grampacyat_ID"] + ",";
                }
            }
            for (int i = 0; i < GvGrampacyatBin.Rows.Count; i++)
            {
                string[] split    = lblSelectedRecord.Text.Split(',');
                Label    lblconid = (Label)GvGrampacyatBin.Rows[i].FindControl("lblGrampacyatId");
                for (int j = 0; j < lblSelectedRecord.Text.Split(',').Length; j++)
                {
                    if (lblSelectedRecord.Text.Split(',')[j] != "")
                    {
                        if (lblconid.Text.Trim().ToString() == lblSelectedRecord.Text.Split(',')[j].Trim().ToString())
                        {
                            ((CheckBox)GvGrampacyatBin.Rows[i].FindControl("chkgvSelect")).Checked = true;
                        }
                    }
                }
            }
        }
        else
        {
            lblSelectedRecord.Text = "";
            DataTable dtGrampacyat1 = (DataTable)Session["dtBinFilter"];
            GvGrampacyatBin.DataSource = dtGrampacyat1;
            GvGrampacyatBin.DataBind();
            ViewState["Select"] = null;
        }
    }
    protected void btnbindBin_Click(object sender, EventArgs e)
    {
        string condition = string.Empty;

        if (ddlOptionBin.SelectedIndex != 0)
        {
            if (ddlOptionBin.SelectedIndex == 1)
            {
                condition = "convert(" + ddlFieldNameBin.SelectedValue + ",System.String)='" + txtValueBin.Text + "'";
            }
            else if (ddlOptionBin.SelectedIndex == 2)
            {
                condition = "convert(" + ddlFieldNameBin.SelectedValue + ",System.String) like '%" + txtValueBin.Text + "%'";
            }
            else
            {
                condition = "convert(" + ddlFieldNameBin.SelectedValue + ",System.String) Like '" + txtValueBin.Text + "%'";
            }

            DataTable dtCust = (DataTable)Session["dtBinGrampacyat"];
            DataView  view   = new DataView(dtCust, condition, "", DataViewRowState.CurrentRows);
            Session["dtBinFilter"]     = view.ToTable();
            lblTotalRecordsBin.Text    = Resources.Attendance.Total_Records + " : " + view.ToTable().Rows.Count.ToString() + "";
            GvGrampacyatBin.DataSource = view.ToTable();
            GvGrampacyatBin.DataBind();

            lblSelectedRecord.Text = "";
            if (view.ToTable().Rows.Count == 0)
            {
                imgBtnRestore.Visible   = false;
                ImgbtnSelectAll.Visible = false;
            }
            else
            {
                AllPageCode();
            }
            System.Web.UI.ScriptManager.GetCurrent(this).SetFocus(txtValueBin);
        }
    }
    public void FillGridBin()
    {
        DataTable dt = new DataTable();

        dt = objDesg.GetGrampacyatMasterInactive(Session["CompId"].ToString().ToString());
        GvGrampacyatBin.DataSource = dt;
        GvGrampacyatBin.DataBind();
        Session["dtBinGrampacyat"] = dt;
        Session["dtBinFilter"]     = dt;
        lblTotalRecordsBin.Text    = Resources.Attendance.Total_Records + ": " + dt.Rows.Count.ToString() + "";

        lblSelectedRecord.Text = "";
        if (dt.Rows.Count == 0)
        {
            imgBtnRestore.Visible   = false;
            ImgbtnSelectAll.Visible = false;
        }
        else
        {
            AllPageCode();
        }
    }