protected void onDelete(object source, CommandEventArgs e)
    {
        int retval = BLL_PURC_ItemLocation.DeleteLocation(Convert.ToInt32(e.CommandArgument.ToString()), Convert.ToInt32(Session["USERID"].ToString()));

        BindLocation();
        UpdPnlGrid.Update();
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (HiddenFlag.Value == "Add")
        {
            int responseid = BLL_PURC_ItemLocation.InsertLocation(Convert.ToInt32(ddlPLocation.SelectedValue), txtLocation.Text.Trim(), Convert.ToInt32(Session["USERID"]));
        }
        else
        {
            int responseid = BLL_PURC_ItemLocation.UpdateLocation(Convert.ToInt32(txtLocationID.Text), Convert.ToInt32(ddlPLocation.SelectedValue), txtLocation.Text.Trim(), Convert.ToInt32(Session["USERID"]));
        }

        BindLocation();

        string hidemodal = String.Format("hideModal('divadd')");

        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "hidemodal", hidemodal, true);
    }
    public void LoadPLocation()
    {
        DataTable dt = BLL_PURC_ItemLocation.GetParentLocation();

        ddlPLocation.DataSource     = dt;
        ddlPLocation.DataTextField  = "Parent_Name";
        ddlPLocation.DataValueField = "Location_ID";
        ddlPLocation.DataBind();
        ddlPLocation.Items.Insert(0, new ListItem("-SELECT ALL-", "0"));
        ddlPLocation.SelectedIndex = 0;

        ddlAddLocation.DataSource     = dt;
        ddlAddLocation.DataTextField  = "Parent_Name";
        ddlAddLocation.DataValueField = "Location_ID";
        ddlAddLocation.DataBind();
        ddlAddLocation.Items.Insert(0, new ListItem("-SELECT ALL-", "0"));
        ddlAddLocation.SelectedIndex = 0;
    }
    public void BindLocation()
    {
        int rowcount = 1;

        string sortbycoloumn = (ViewState["SORTBYCOLOUMN"] == null) ? null : (ViewState["SORTBYCOLOUMN"].ToString());
        int?   sortdirection = null; if (ViewState["SORTDIRECTION"] != null)
        {
            sortdirection = Int32.Parse(ViewState["SORTDIRECTION"].ToString());
        }



        DataTable dt = BLL_PURC_ItemLocation.GetLocation_Search(UDFLib.ConvertIntegerToNull(ddlPLocation.SelectedValue), txtSearchBy.Text, sortbycoloumn, sortdirection, ucCustomPagerItems.CurrentPageIndex, ucCustomPagerItems.PageSize, ref rowcount);

        gvLocation.DataSource = dt;
        gvLocation.DataBind();

        ucCustomPagerItems.CountTotalRec = rowcount.ToString();
        ucCustomPagerItems.BuildPager();
    }
    protected void onUpdate(object source, CommandEventArgs e)
    {
        HiddenFlag.Value = "Edit";
        OperationMode    = "Edit Location";

        DataTable dt = new DataTable();

        dt = BLL_PURC_ItemLocation.EditLocation(Convert.ToInt32(e.CommandArgument.ToString()));
        if (dt.Rows.Count > 0)
        {
            txtLocationID.Text           = dt.Rows[0]["Location_ID"].ToString();
            txtLocation.Text             = dt.Rows[0]["Location_Name"].ToString();
            ddlAddLocation.SelectedValue = dt.Rows[0]["Parent_ID"].ToString();
            ddlAddLocation.Enabled       = false;
        }

        string Countrymodal = String.Format("showModal('divadd',false);");

        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Countrymodal", Countrymodal, true);
    }
    protected void btnExport_Click(object sender, ImageClickEventArgs e)
    {
        int rowcount = ucCustomPagerItems.isCountRecord;

        string sortbycoloumn = (ViewState["SORTBYCOLOUMN"] == null) ? null : (ViewState["SORTBYCOLOUMN"].ToString());
        int?   sortdirection = null; if (ViewState["SORTDIRECTION"] != null)
        {
            sortdirection = Int32.Parse(ViewState["SORTDIRECTION"].ToString());
        }



        DataTable dt = BLL_PURC_ItemLocation.GetLocation_Search(UDFLib.ConvertIntegerToNull(ddlPLocation.SelectedValue), txtSearchBy.Text, sortbycoloumn, sortdirection, null, null, ref rowcount);



        string[] HeaderCaptions  = { "Parent Name", "Location Name" };
        string[] DataColumnsName = { "Parent_Name", "Location_Name" };

        GridViewExportUtil.ShowExcel(dt, HeaderCaptions, DataColumnsName, "Item Location", "Item Location");
    }