コード例 #1
0
        // prress key for update and delete student
        private void gvStudents_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (gvStudents.SelectedCells.Count > 0)
                {
                    int             selectedrowindex = gvStudents.SelectedCells[0].RowIndex;
                    DataGridViewRow selectedRow      = gvStudents.Rows[selectedrowindex];
                    string          _id = Convert.ToString(selectedRow.Cells["id"].Value);
                    lblidStud.Text = _id;
                    string  _qry = "";
                    DataSet ds   = new DataSet();
                    string  qry  = "SELECT        Student.Id, Student.FirstName, Student.LastName, Student.Contact, Student.Email, Student.RegistrationNumber, Lookup.Name, Lookup.LookupId " +
                                   " FROM  Student INNER JOIN " + " Lookup ON Student.Status = Lookup.LookupId where id='" + _id + "'";

                    ds = ajdbClass.GetRecords("tbl", qry);
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        txtfname.Text           = dr["FirstName"].ToString().Trim();
                        txtlname.Text           = dr["LastName"].ToString().Trim();
                        txtcon.Text             = dr["Contact"].ToString().Trim();
                        txtemail.Text           = dr["Email"].ToString().Trim();
                        txtRegNo.Text           = dr["RegistrationNumber"].ToString().Trim();
                        cmbStatus.SelectedValue = dr["LookupId"].ToString().Trim();
                    }
                }
            }
            //delete student
            if (e.KeyCode == Keys.Delete)
            {
                if (AskYesNo() == false)
                {
                    return;
                }
                int             selectedrowindex = gvStudents.SelectedCells[0].RowIndex;
                DataGridViewRow selectedRow      = gvStudents.Rows[selectedrowindex];
                string          _id = Convert.ToString(selectedRow.Cells["id"].Value);

                string s = ajdbClass.DeleteFromDatabase("delete from student where id='" + _id + "'");
                if (s != "Delete Record(s) Successfully")
                {
                    s = "Unable to Delete. Record might be required in other tables";
                }
                MessageBox.Show(s);

                string qry = "SELECT Student.Id, Student.FirstName, Student.LastName, Student.Contact, Student.Email, Student.RegistrationNumber, Lookup.Name, Lookup.LookupId " +
                             " FROM Student INNER JOIN " + " Lookup ON Student.Status = Lookup.LookupId ";
                ajdbClass.popGrid(gvStudents, qry);
                txtfname.Text = ""; txtlname.Text = ""; txtRegNo.Text = ""; txtemail.Text = ""; txtcon.Text = "";
            }
        }
コード例 #2
0
        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            GridViewRow  row         = (GridViewRow)GridView1.Rows[e.RowIndex];
            Label        lbldeleteid = (Label)row.FindControl("lblID");
            AJ_DataClass aj          = new AJ_DataClass();

            aj.DeleteFromDatabase("delete FROM Purchase where Prid='" + Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value.ToString()) + "'");
            gvbind();
        }
コード例 #3
0
 // delete rows from clos
 private void gvClo_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Delete)
     {
         if (AskYesNo() == false)
         {
             return;
         }
         int             selectedrowindex = gvClo.SelectedCells[0].RowIndex;
         DataGridViewRow selectedRow      = gvClo.Rows[selectedrowindex];
         string          _id       = Convert.ToString(selectedRow.Cells["id"].Value);
         AJ_DataClass    ajdbClass = new AJ_DataClass();
         string          s         = ajdbClass.DeleteFromDatabase("delete from clo where id='" + _id + "'");
         ajdbClass.popGrid(gvClo, "select id,name from clo");
         ajdbClass.popCmb(cmbClo, "select * from clo", "id", "name");
         lblrubricLevels.Text = "Rubrics Level - Settings Clo:" + cmbClo.Text;
     }
 }