void BindData1()
 {
     if (!string.IsNullOrEmpty(txtSearchDivisionName.Text))
     {
         ClassDivision d1 = new ClassDivision();
         DataTable dt1 = d1.GetDivision(txtSearchDivisionName.Text, "", "");
         GridView1.DataSource = dt1;
         GridView1.DataBind();
         SetViewState(dt1);
     }
     if (ddlSearchCampus.SelectedIndex != 0)
     {
         ClassDivision d2 = new ClassDivision();
         DataTable dt2 = d2.GetDivision("", ddlSearchCampus.SelectedValue, "");
         GridView1.DataSource = dt2;
         GridView1.DataBind();
         SetViewState(dt2);
     }
     if (ddlSearchFaculty.SelectedIndex != 0)
     {
         ClassDivision d3 = new ClassDivision();
         DataTable dt3 = d3.GetDivision("", "", ddlSearchFaculty.SelectedValue);
         GridView1.DataSource = dt3;
         GridView1.DataBind();
         SetViewState(dt3);
     }
 }
 protected void lbuRefresh_Click(object sender, EventArgs e)
 {
     ClearData();
     ClassDivision d = new ClassDivision();
     DataTable dt = d.GetDivision("", "", "");
     GridView1.DataSource = dt;
     GridView1.DataBind();
     SetViewState(dt);
 }
 void BindData()
 {
     ClassDivision d = new ClassDivision();
     DataTable dt = d.GetDivision("", "", "");
     GridView1.DataSource = dt;
     GridView1.DataBind();
     SetViewState(dt);
 }
        protected void modUpdateCommand(Object sender, GridViewUpdateEventArgs e)
        {
            Label lblDivisionIDEdit = (Label)GridView1.Rows[e.RowIndex].FindControl("lblDivisionIDEdit");
            TextBox txtDivisionNameEdit = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtDivisionNameEdit");
            DropDownList ddlCampusIDEdit = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("ddlCampusIDEdit");
            DropDownList ddlFacultyIDEdit = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("ddlFacultyIDEdit");

            ClassDivision d = new ClassDivision(Convert.ToInt32(lblDivisionIDEdit.Text)
                , txtDivisionNameEdit.Text
                , Convert.ToInt32(ddlCampusIDEdit.SelectedValue)
                , Convert.ToInt32(ddlFacultyIDEdit.SelectedValue));

            if (d.CheckUseDivisionName())
            {
                d.UpdateDivision();
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('อัพเดทข้อมูลเรียบร้อย')", true);
                GridView1.EditIndex = -1;
                BindData1();
            }
            else
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('ข้อมูลที่จะอัพเดท มีอยู่ในระบบแล้ว !')", true);
            }
        }
        protected void modDeleteCommand(Object sender, GridViewDeleteEventArgs e)
        {
            int id = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value);
            ClassDivision d = new ClassDivision();
            d.DIVISION_ID = id;
            d.DeleteDivision();
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('ลบข้อมูลเรียบร้อย')", true);

            if (txtSearchDivisionName.Text != "" || ddlSearchCampus.SelectedIndex != 0 || ddlSearchFaculty.SelectedIndex != 0)
            {
                GridView1.EditIndex = -1; ;
                BindData1();
            }
            else
            {
                GridView1.EditIndex = -1; ;
                BindData();
            }
        }
        protected void lbuSubmit_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtInsertDivisionName.Text))
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('กรุณาใส่ ชื่อกอง / สำนักงานเลขา / ภาควิชา')", true);
                return;
            }
            if (ddlInsertCampus.SelectedIndex == 0)
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('กรุณาเลือก วิทยาเขต')", true);
                return;
            }
            if (ddlInsertFaculty.SelectedIndex == 0)
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('กรุณาเลือก สำนัก / สถาบัน / คณะ')", true);
                return;
            }
            ClassDivision d = new ClassDivision();
            d.DIVISION_NAME = txtInsertDivisionName.Text;
            d.CAMPUS_ID = Convert.ToInt32(ddlInsertCampus.SelectedValue);
            d.FACULTY_ID = Convert.ToInt32(ddlInsertFaculty.SelectedValue);

            if (d.CheckUseDivisionName())
            {
                d.InsertDivision();
                BindData();
                ClearData();
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('เพิ่มข้อมูลเรียบร้อย')", true);
            }
            else
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('ข้อมูลที่จะเพิ่ม มีอยู่ในระบบแล้ว !')", true);
            }
        }
        protected void lbuSearch_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtSearchDivisionName.Text) && ddlSearchCampus.SelectedIndex == 0 && ddlSearchFaculty.SelectedIndex == 0)
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('กรุณากรอก คำค้นหา')", true);

                return;
            }
            else
            {
                if (!string.IsNullOrEmpty(txtSearchDivisionName.Text))
                {
                    ClassDivision d1 = new ClassDivision();
                    DataTable dt1 = d1.GetDivision(txtSearchDivisionName.Text, "", "");
                    GridView1.DataSource = dt1;
                    GridView1.DataBind();
                    SetViewState(dt1);
                }
                if (ddlSearchCampus.SelectedIndex != 0)
                {
                    ClassDivision d2 = new ClassDivision();
                    DataTable dt2 = d2.GetDivision("", ddlSearchCampus.SelectedValue, "");
                    GridView1.DataSource = dt2;
                    GridView1.DataBind();
                    SetViewState(dt2);
                }
                if (ddlSearchFaculty.SelectedIndex != 0)
                {
                    ClassDivision d3 = new ClassDivision();
                    DataTable dt3 = d3.GetDivision("", "", ddlSearchFaculty.SelectedValue);
                    GridView1.DataSource = dt3;
                    GridView1.DataBind();
                    SetViewState(dt3);
                }
            }
        }