protected void btnarea_Click(object sender, EventArgs e)
    {
        ViewState["SelectedMode"] = "Area";
        fillCity();
        lblName.Visible      = true;
        drpSelection.Visible = true;
        lblName.Text         = "Select City";
        DataSet dsArea = new DataSet();

        GvLocation.DataKeyNames = new string[] { "AreaID" };
        //if (ViewState["CountryId"] != null)
        //{
        List <ParaList> para = new List <ParaList>()
        {
            new ParaList {
                Key = "@mode", Value = "Area"
            },
            new ParaList {
                Key = "@i_CompId", Value = CurrentUser.CompId
            },
        };


        dsArea = crmclient.list(para, "Area");
        if (dsArea.Tables[0].Rows.Count > 0)
        {
            GvLocation.DataSource = dsArea.Tables[0];
            GvLocation.DataBind();
        }
        else
        {
            GvLocation.DataSource = ReturnEmptyRow();
            GvLocation.DataBind();
        }
    }
    protected void btnCountry_Click(object sender, EventArgs e)
    {
        ViewState["SelectedMode"] = "Country";
        DataSet dscountry = new DataSet();

        fillCountry();
        lblName.Visible      = false;
        drpSelection.Visible = false;

        DataSet dsstate = new DataSet();

        GvLocation.DataKeyNames = new string[] { "CountryId" };

        List <ParaList> para = new List <ParaList>()
        {
            new ParaList {
                Key = "@mode", Value = "Country"
            },
            new ParaList {
                Key = "@i_CompId", Value = CurrentUser.CompId
            },
        };

        dsCountry             = crmclient.list(para, "Country");
        GvLocation.DataSource = dsCountry.Tables[0];
        GvLocation.DataBind();
        //ViewState["SelectedMode"] = "State";
        //}
    }
    protected void btnCity_Click(object sender, EventArgs e)
    {
        ViewState["SelectedMode"] = "City";
        fillState();
        lblName.Visible      = true;
        drpSelection.Visible = true;
        lblName.Text         = "Select State";
        DataSet dsstate = new DataSet();

        GvLocation.DataKeyNames = new string[] { "CityID" };
        //if (ViewState["CountryId"] != null)
        //{
        List <ParaList> para = new List <ParaList>()

        {
            new ParaList {
                Key = "@mode", Value = "City"
            },
            new ParaList {
                Key = "@i_StateID", Value = drpSelection.SelectedValue
            },
            new ParaList {
                Key = "@i_CompID", Value = CurrentUser.CompId
            },
        };

        dsstate = crmclient.list(para, "City");
        GvLocation.DataSource = dsstate.Tables[0];
        GvLocation.DataBind();
    }
    public void bindAreaData()
    {
        DataSet ds = new DataSet();

        GvLocation.DataKeyNames = new string[] { "AreaID" };
        //if (ViewState["CountryId"] != null)
        //{
        List <ParaList> para = new List <ParaList>()
        {
            new ParaList {
                Key = "@mode", Value = "Area"
            },
            new ParaList {
                Key = "@i_CompId", Value = CurrentUser.CompId
            },
        };

        ds = crmclient.list(para, "Area");

        if (ds.Tables[0].Rows.Count > 0)
        {
            GvLocation.DataSource = ds.Tables[0];
            GvLocation.DataBind();
        }
        else
        {
            GvLocation.DataSource = ReturnEmptyRow();
            GvLocation.DataBind();
        }
    }
    public void bindStateData()
    {
        DataSet ds = new DataSet();

        GvLocation.DataKeyNames = new string[] { "StateID" };
        //if (ViewState["CountryId"] != null)
        //{
        List <ParaList> para = new List <ParaList>()
        {
            new ParaList {
                Key = "@mode", Value = "State"
            },
            new ParaList {
                Key = "@i_compid", Value = CurrentUser.CompId
            },
        };

        ds = crmclient.list(para, "State");
        GvLocation.DataSource = ds.Tables[0];
        GvLocation.DataBind();
    }
    public void bindCountrydata()
    {
        //foreach (GridView row in GvLocation.Rows)
        //{
        //    LinkButton btnselect = (LinkButton)GvLocation.FindControl("btnselect");
        //    btnselect.CommandArgument = "CountryId";

        //}
        List <ParaList> para = new List <ParaList>()
        {
            new ParaList {
                Key = "@mode", Value = "Country"
            },
            new ParaList {
                Key = "@i_CompId", Value = CurrentUser.CompId
            },
        };


        dsCountry             = crmclient.list(para, "Country");
        GvLocation.DataSource = dsCountry.Tables[0];
        GvLocation.DataBind();
    }
    public void bindCityData()
    {
        DataSet ds = new DataSet();

        GvLocation.DataKeyNames = new string[] { "CityId" };
        //if (ViewState["CountryId"] != null)
        //{
        List <ParaList> para = new List <ParaList>()
        {
            new ParaList {
                Key = "@mode", Value = "City"
            },
            new ParaList {
                Key = "@i_StateID", Value = drpSelection.SelectedValue
            },
            new ParaList {
                Key = "@i_CompID", Value = CurrentUser.CompId
            },
        };

        ds = crmclient.list(para, "City");
        GvLocation.DataSource = ds.Tables[0];
        GvLocation.DataBind();
    }
    protected void drpSelection_SelectedIndexChanged(object sender, EventArgs e)
    {
        DataSet ds = new DataSet();

        ViewState["SelectedId"] = drpSelection.SelectedValue.ToString();
        if (ViewState["SelectedMode"].ToString() == "State")
        {
            if (ViewState["SelectedId"] != null)
            {
                List <ParaList> para = new List <ParaList>()
                {
                    new ParaList {
                        Key = "@i_id", Value = ViewState["SelectedId"].ToString()
                    },
                    new ParaList {
                        Key = "@i_CompId", Value = CurrentUser.CompId
                    },
                };

                ds = crmclient.LOV(para, "State");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    GvLocation.DataSource = ds.Tables[0];
                    GvLocation.DataBind();
                }
                else
                {
                    GvLocation.DataSource = ReturnEmptyRow();
                    GvLocation.DataBind();
                }
            }
        }
        if (ViewState["SelectedMode"].ToString() == "City")
        {
            if (ViewState["SelectedId"] != null)
            {
                List <ParaList> para = new List <ParaList>()
                {
                    new ParaList {
                        Key = "@i_id", Value = ViewState["SelectedId"].ToString()
                    },
                    new ParaList {
                        Key = "@i_compid", Value = CurrentUser.CompId
                    },
                };

                ds = crmclient.LOV(para, "City");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    GvLocation.DataSource = ds.Tables[0];
                    GvLocation.DataBind();
                }
                else
                {
                    GvLocation.DataSource = ReturnEmptyRow();
                    GvLocation.DataBind();
                }
            }
        }

        if (ViewState["SelectedMode"].ToString() == "Area")
        {
            if (ViewState["SelectedId"] != null)
            {
                List <ParaList> para = new List <ParaList>()
                {
                    new ParaList {
                        Key = "@i_id", Value = ViewState["SelectedId"].ToString()
                    },
                    new ParaList {
                        Key = "@i_CompId", Value = CurrentUser.CompId
                    },
                };

                ds = crmclient.LOV(para, "Area");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    GvLocation.DataSource = ds.Tables[0];
                    GvLocation.DataBind();
                }
                else
                {
                    GvLocation.DataSource = ReturnEmptyRow();
                    GvLocation.DataBind();
                }
            }
        }
    }