public static void FillDropDownListCatagory(DropDownList ddl, SqlString CatagoryType, SqlInt32 UserID)
    {
        CatagoryBAL balCatagory = new CatagoryBAL();

        ddl.DataSource     = balCatagory.SelectForDropDownList(CatagoryType, UserID);
        ddl.DataTextField  = "CatagoryName";
        ddl.DataValueField = "CatagoryID";
        ddl.DataBind();

        ddl.Items.Insert(0, new ListItem("Select Catagory", "-1"));
    }
    protected void lbtnDeleteCatagory_Click(object sender, EventArgs e)
    {
        CatagoryBAL balCatagory = new CatagoryBAL();

        foreach (GridViewRow gvRow in gvCatagory.Rows)
        {
            CheckBox chkDeleteCatagory = (CheckBox)gvRow.FindControl("chkCatagory");
            if (chkDeleteCatagory.Checked)
            {
                int CatagoryID = Convert.ToInt32(gvCatagory.DataKeys[gvRow.RowIndex].Value.ToString());
                balCatagory.Delete(CatagoryID, Convert.ToInt32(Session["UserID"].ToString()));
            }
        }
        FillGridViewCatagory(Convert.ToInt32(Session["UserID"].ToString()));
    }
    private void FillControls(SqlInt32 CatagoryID, SqlInt32 UserID)
    {
        CatagoryBAL balCatagory = new CatagoryBAL();
        CatagoryENT entCatagory = new CatagoryENT();

        entCatagory = balCatagory.SelectByPK(CatagoryID, UserID);

        if (!entCatagory.CatagoryName.IsNull)
        {
            txtCatagoryName.Text = entCatagory.CatagoryName.Value;
        }

        if (!entCatagory.CatagoryType.IsNull)
        {
            rbCatagoryType.Text = entCatagory.CatagoryType.Value;
        }

        if (!entCatagory.CatagoryDescripation.IsNull)
        {
            txtDescripation.Text = entCatagory.CatagoryDescripation.Value;
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        #region Server Side Validation
        string strError = "";

        if (txtCatagoryName.Text.Trim() == "")
        {
            strError += "Enter Catagory Name";
        }

        if (rbCatagoryType.Text.Trim() == "")
        {
            strError += "Enter Catagory Type";
        }

        if (strError.Trim() != "")
        {
            lblErrorMessage.Text = strError;
            divMessage.Visible   = true;
            return;
        }
        #endregion Server Side Validation

        #region Collect Data
        CatagoryENT entCatagory = new CatagoryENT();

        if (txtCatagoryName.Text != "")
        {
            entCatagory.CatagoryName = txtCatagoryName.Text;
        }

        if (rbCatagoryType.Text != "")
        {
            entCatagory.CatagoryType = rbCatagoryType.Text;
        }

        if (txtDescripation.Text != "")
        {
            entCatagory.CatagoryDescripation = txtDescripation.Text;
        }

        if (Session["UserID"] != null)
        {
            entCatagory.UserID = Convert.ToInt32(Session["UserID"].ToString());
        }

        #endregion Collect Data

        CatagoryBAL balCatagory = new CatagoryBAL();

        if (hfCatagoryID.Value == "")
        {
            if (balCatagory.Insert(entCatagory))
            {
                lblErrorMessage.Text     = "Data Insert Successfully...";
                lblErrorMessage.CssClass = "text-success";
                divMessage.Visible       = true;
                ClearControls();
            }
            else
            {
                lblErrorMessage.Text = balCatagory.Message;
            }
        }
        else
        {
            entCatagory.CatagoryID = Convert.ToInt32(hfCatagoryID.Value.ToString().Trim());

            if (balCatagory.Update(entCatagory))
            {
                lblErrorMessage.Text = "Data Updated Successfully...";
                divMessage.Visible   = true;
                ClearControls();
            }
            else
            {
                lblErrorMessage.Text = balCatagory.Message;
            }
        }
        FillGridViewCatagory(Convert.ToInt32(Session["UserID"].ToString()));
        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "#add-contact", "$('body').removeClass('modal-open');$('.modal-backdrop').remove();", true);
    }