iam using this code but it not working
private void dgvstudentreg_CellContentClick_1(object sender, DataGridViewCellEventArgs e)
{
if (dgvstudentreg.CurrentCell.Value.ToString() == "Edit")
{
cs_field.Code = dgvstudentreg.SelectedRows[0].Cells[0].Value.ToString();
txtRegno.Text = dgvstudentreg.CurrentRow.Cells["_regno"].Value.ToString();
txtFName.Text = dgvstudentreg.CurrentRow.Cells["fname"].Value.ToString();
txtMName.Text = dgvstudentreg.CurrentRow.Cells["mname"].Value.ToString();
txtLName.Text = dgvstudentreg.CurrentRow.Cells["lname"].Value.ToString();
txtBloodGrp.Text = dgvstudentreg.CurrentRow.Cells["Bloodgrp"].Value.ToString();
txtHeight.Text = dgvstudentreg.CurrentRow.Cells["Height"].Value.ToString();
txtWeight.Text = dgvstudentreg.CurrentRow.Cells["Weight"].Value.ToString();
dtpBirthDate.Text = dgvstudentreg.CurrentRow.Cells["DateOfBirth"].Value.ToString();
cmbGender.Text = dgvstudentreg.CurrentRow.Cells["Gender"].Value.ToString();
txtCast.Text = dgvstudentreg.CurrentRow.Cells["Cast"].Value.ToString();
pic_SPhoto.ImageLocation = dgvstudentreg.CurrentRow.Cells["Photo"].Value.ToString();
txtCAddress.Text = dgvstudentreg.CurrentRow.Cells["CAddress"].Value.ToString();
txtPAddress.Text = dgvstudentreg.CurrentRow.Cells["PAddress"].Value.ToString();
txtMobileno1.Text = dgvstudentreg.CurrentRow.Cells["MobileNo1"].Value.ToString();
//txtMobileno2.Text = dgvstudentreg.CurrentRow.Cells["MobileNo2"].Value.ToString();
// txtEmailid.Text = dgvstudentreg.CurrentRow.Cells["EmailId"].Value.ToString();
txtFatherfullname.Text = dgvstudentreg.CurrentRow.Cells["FatherName"].Value.ToString();
txtFoccupation.Text = dgvstudentreg.CurrentRow.Cells["FatherOccupation"].Value.ToString();
txtF_Mobileno.Text = dgvstudentreg.CurrentRow.Cells["FatherMobileno"].Value.ToString();
//txtF_Officeno.Text = dgvstudentreg.CurrentRow.Cells["FatherOfficeno"].Value.ToString();
txtMotherfullname.Text = dgvstudentreg.CurrentRow.Cells["MotherName"].Value.ToString();
txtMoccupation.Text = dgvstudentreg.CurrentRow.Cells["MotherOccupation"].Value.ToString();
txtM_Mobileno.Text = dgvstudentreg.CurrentRow.Cells["MotherMobileNo"].Value.ToString();
//txtM_Officeno.Text = dgvstudentreg.CurrentRow.Cells["MotherOfficeNo"].Value.ToString();
txtP_Schoolname.Text = dgvstudentreg.CurrentRow.Cells["PrvSchoolName"].Value.ToString();
txtP_Durationform.Text = dgvstudentreg.CurrentRow.Cells["PrvDurationfor"].Value.ToString();
txtP_Durationto.Text = dgvstudentreg.CurrentRow.Cells["PrvDurationto"].Value.ToString();
txtP_Class.Text = dgvstudentreg.CurrentRow.Cells["PrvClass"].Value.ToString();
//txtP_Marks.Text = dgvstudentreg.CurrentRow.Cells["PrvMarks"].Value.ToString();
txtP_Contactno.Text = dgvstudentreg.CurrentRow.Cells["PrvSchoolcontno"].Value.ToString();
btnSave.Text = "&Update";
btnNew.Enabled = true;
btnSave.Enabled = true;
}
if (dgvstudentreg.CurrentCell.Value.ToString() == "Delete")
{
if (DialogResult.Yes == MessageBox.Show("\tAre you sure to Delete this Student Details?\t\t", "Delete?", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
{
//cs_field.Code1 = dgvstudentreg.CurrentRow.Cells["_regno"].Value.ToString();
txtRegno.Text = dgvstudentreg.CurrentRow.Cells["_regno"].Value.ToString();
cs_field.Code = txtRegno.Text;
cs_studentreg.Deletestudent(cs_field);
ClearField();
MessageBox.Show("\t Student Details Deleted Successfully.\t\t", "Deleted", MessageBoxButtons.OK, MessageBoxIcon.Information);
frmStudentRegistration_Load(this, EventArgs.Empty);
btnSave.Text = "Save";
}
}
}