protected void butSubmit_Click(object sender, EventArgs e)
    {
        int Active;

        if (butSubmit.Text == "Submit")
        {
            if (ddlstatus.SelectedItem.Text == "Active")
            {
                Active = 1;
            }
            else
            {
                Active = 0;
            }
            string     sr123 = "Select * from [RoleMaster] where Role_name='" + txtRole.Text + "' and compid='" + Session["comid"] + "' ";
            SqlCommand cm123 = new SqlCommand(sr123, con);
            cm123.CommandType = CommandType.Text;
            SqlDataAdapter da123 = new SqlDataAdapter(cm123);
            DataTable      ds123 = new DataTable();
            da123.Fill(ds123);
            if (ds123.Rows.Count > 0)
            {
                Label2.Visible = true;
                Label2.Text    = "Record already exists";
            }
            else
            {
                obj.insertrolemaster(txtRole.Text, Active, compid);
                Label2.Visible = true;
                Label2.Text    = "Record inserted successfully";
                pnladd.Visible = false;
                btnadd.Visible = true;
                lbladd.Text    = "";
                SqlDataAdapter adpt = new SqlDataAdapter("Select Max(Role_id) as roleid from RoleMaster", con);
                DataTable      dt   = new DataTable();
                adpt.Fill(dt);
                if (CheckBox1.Checked == true)
                {
                    string te = "Page_role_Access.aspx?id=" + dt.Rows[0]["roleid"].ToString();
                    ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", "window.open('" + te + "');", true);
                }
            }
        }
        else
        {
            if (ddlstatus.SelectedItem.Text == "Active")
            {
                Active = 1;
            }
            else
            {
                Active = 0;
            }
            string     sr123 = "Select * from [RoleMaster] where Role_name='" + txtRole.Text + "' and compid='" + Session["comid"] + "' and Role_id<>'" + Int16.Parse(lblrole_id.Text) + "'";
            SqlCommand cm123 = new SqlCommand(sr123, con);
            cm123.CommandType = CommandType.Text;
            SqlDataAdapter da123 = new SqlDataAdapter(cm123);
            DataTable      ds123 = new DataTable();
            da123.Fill(ds123);
            if (ds123.Rows.Count > 0)
            {
                Label2.Visible = true;
                Label2.Text    = "Record already exists";
            }
            else
            {
                obj.updateRolemaster(Int16.Parse(lblrole_id.Text), txtRole.Text, Active);
                Label2.Visible = true;
                Label2.Text    = "Record updated successfully";
                butSubmit.Text = "Submit";
                pnladd.Visible = false;
                btnadd.Visible = true;
                lbladd.Text    = "";

                CheckBox1.Visible = true;
            }
        }



        txtRole.Text = "";
        //raActive.Checked = true;
        //raDeactive.Checked = false;
        ddlstatus.SelectedIndex = 0;
        fillgrid();
    }