protected void DeleteItem_Click(object sender, EventArgs e)
 {
     try
     {
         LinkButton btn = sender as LinkButton;
         switch (btn.CommandName)
         {
         case "Delete":
             try
             {
                 int id = Convert.ToInt32(btn.CommandArgument);
                 SAP_Vendor_Items obj = db.SAP_Vendor_Items.Find(id);
                 db.SAP_Vendor_Items.Remove(obj);
                 db.SaveChanges();
                 this.ErrorMessage = "Record successfully deleted.";
                 //BindListItems(this.gvListItems, this.Category);
                 gvListItems.DataBind();
             }
             catch (Exception ex)
             {
                 this.ErrorMessage = ex.Message;
             }
             break;
         }
     }
     catch (Exception ex)
     {
         this.ErrorMessage = ex.Message;
     }
 }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            SAP_Vendor_Items obj = new SAP_Vendor_Items();

            try
            {
                if (!Validation())
                {
                    return;
                }
                bool isExisted = false;
                if (this.Id > 0)
                {
                    obj = db.SAP_Vendor_Items.Find(this.Id);
                    if (obj != null)
                    {
                        isExisted = true;
                    }
                    else
                    {
                        obj = new SAP_Vendor_Items();
                    }
                }

                obj.Description = txtTitle.Text;
                obj.Value       = txtTitle.Text;
                obj.Category    = this.Category;
                obj.Enable      = "1";
                if (isExisted)
                {
                    db.SAP_Vendor_Items.Attach(obj);
                    db.Entry(obj).State = EntityState.Modified;
                }
                else
                {
                    db.SAP_Vendor_Items.Add(obj);
                }
                db.SaveChanges();

                this.ErrorMessage = "Record successfully saved.";
                gvListItems.DataBind();
                btnReset_Click(btnReset, e);
            }
            catch (Exception ex)
            {
                this.ErrorMessage = ex.Message;
            }
        }
        protected void gvListItems_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            try
            {
                GridView         gridView = sender as GridView;
                int              index    = -1;
                SAP_Vendor_Items obj      = null;
                switch (e.CommandName)
                {
                case "Delete":

                    try
                    {
                        index = Convert.ToInt32(e.CommandArgument);
                        gridView.SelectedIndex = index;
                        obj = db.SAP_Vendor_Items.Find((int)gridView.SelectedDataKey["Id"]);

                        db.SAP_Vendor_Items.Remove(obj);
                        db.SaveChanges();
                        gridView.SelectedIndex = -1;
                        this.ErrorMessage      = "Record successfully deleted.";
                        gridView.DataBind();
                    }
                    catch (Exception ex)
                    {
                        this.ErrorMessage = ex.Message;
                    }
                    break;

                case "Select":
                    index = Convert.ToInt32(e.CommandArgument);
                    gridView.SelectedIndex = index;
                    obj = db.SAP_Vendor_Items.Find((int)gridView.SelectedDataKey["Id"]);
                    SelectItem(obj);
                    break;
                }
            }
            catch (Exception ex)
            {
                this.ErrorMessage = ex.Message;
            }
        }
        protected void SelectItem(SAP_Vendor_Items obj)
        {
            try
            {
                if (obj == null)
                {
                    return;
                }
                if (!string.IsNullOrEmpty(obj.Category))
                {
                    General.SelectItemByValue(ddlCategory, obj.Category);
                }

                this.Category          = obj.Category;
                txtTitle.Text          = obj.Description;
                txtValue.Text          = obj.Value;
                this.Id                = obj.Id;
                this.hidRecordID.Value = obj.Id.ToString();
            }
            catch (Exception ex)
            {
                this.ErrorMessage = ex.Message;
            }
        }