//*Start* Code added by Shrikant
    protected void Regiongrdvw_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        string name, desc, id;
        int    Regionid = 0;
        int    FlagRegion;
        int    organizationId;

        objOrganization = objOrganization.Get_Organization();
        organizationId  = objOrganization.Orgid;
        clearControl();
        name      = ((TextBox)Regiongrdvw.Rows[e.RowIndex].Cells[1].Controls[0]).Text;
        desc      = ((TextBox)Regiongrdvw.Rows[e.RowIndex].Cells[3].Controls[0]).Text;
        id        = Convert.ToString(Regiongrdvw.Rows[e.RowIndex].Cells[0].Text);
        Regionid  = Convert.ToInt16(id);
        Regionobj = Regionobj.Get_By_id(Regionid);

        if (Regionobj.Regionname == name)
        {
            Regionobj.Regionname  = name;
            Regionobj.Description = desc;
            Regionobj.Update();
            Regiongrdvw.EditIndex = -1;
            BindGrid();
            lblerrmsg.Text = Resources.MessageResource.errupdate.ToString();
        }
        else
        {
            FlagRegion = Regionobj.Get_By_RegionName(name, organizationId);
            if ((FlagRegion == 0) && (name != ""))
            {
                Regionobj.Regionname  = name;
                Regionobj.Description = desc;
                Regionobj.Update();
                Regiongrdvw.EditIndex = -1;
                BindGrid();
                lblerrmsg.Text = Resources.MessageResource.errupdate.ToString();
            }
            else if (name == "")
            {
                lblerrmsg.Text = Resources.MessageResource.errnotempty.ToString();
            }
            else
            {
                Regiongrdvw.EditIndex = -1;
                BindGrid();
                lblerrmsg.Text = Resources.MessageResource.errRegionExist.ToString();
            }
        }
    }
    protected void btnRegionadd_Click(object sender, EventArgs e)
    {
        int regionid = 0;
        int organizationId;

        objOrganization = objOrganization.Get_Organization();
        organizationId  = objOrganization.Orgid;
        regionid        = Regionobj.Get_By_RegionName(txtregionname.Text.ToString(), organizationId);
        if (regionid == 0)
        {
            Regionobj.Regionname  = txtregionname.Text.ToString();
            Regionobj.Description = txtregiondesc.Text.ToString();
            Regionobj.Orgid       = organizationId;
            Regionobj.Insert();
            BindGrid();
            lblerrmsg.Text = Resources.MessageResource.erradd.ToString();
        }
        else
        {
            lblerrmsg.Text = Resources.MessageResource.errRegionExist.ToString();
        }
        Dispose();
    }
    //*Start* Code added by Shrikant
    protected void Regiongrdvw_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        string name, desc, id;
        int Regionid = 0;
        int FlagRegion;
        int organizationId;

        objOrganization = objOrganization.Get_Organization();
        organizationId=objOrganization.Orgid;
        clearControl();
        name = ((TextBox)Regiongrdvw.Rows[e.RowIndex].Cells[1].Controls[0]).Text;
        desc = ((TextBox)Regiongrdvw.Rows[e.RowIndex].Cells[3].Controls[0]).Text;
        id = Convert.ToString(Regiongrdvw.Rows[e.RowIndex].Cells[0].Text);
        Regionid = Convert.ToInt16(id);
        Regionobj = Regionobj.Get_By_id(Regionid);

            if (Regionobj.Regionname == name)
            {
                Regionobj.Regionname = name;
                Regionobj.Description = desc;
                Regionobj.Update();
                Regiongrdvw.EditIndex = -1;
                BindGrid();
                lblerrmsg.Text = Resources.MessageResource.errupdate.ToString();
            }
            else
            {
                FlagRegion = Regionobj.Get_By_RegionName(name, organizationId);
                if ((FlagRegion == 0)&&(name!=""))
                {
                    Regionobj.Regionname = name;
                    Regionobj.Description = desc;
                    Regionobj.Update();
                    Regiongrdvw.EditIndex = -1;
                    BindGrid();
                    lblerrmsg.Text = Resources.MessageResource.errupdate.ToString();
                }
                else if(name=="")
                {
                    lblerrmsg.Text = Resources.MessageResource.errnotempty.ToString();
                }
                else
                {
                     Regiongrdvw.EditIndex = -1;
                     BindGrid();
                     lblerrmsg.Text = Resources.MessageResource.errRegionExist.ToString();
                }
            }
    }