本文介绍了一键保存和更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
namespace RERMS.HR
{
public partial class LateAttendance : System.Web.UI.Page
{
Button btnSave;
protected void Page_Load(object sender, EventArgs e)
{
(this.Master as SiteMaster).SaveClicked += new EventHandler(Save_Click);
(this.Master as SiteMaster).DeleteClicked += new EventHandler(Delete_Click);
if (!IsPostBack)
{ LoadGridView();
}
if (Request.QueryString["LateAttendanceApprovalID"] == null || Request.QueryString["LateAttendanceApprovalID"].ToString() == "")
{}
else if (Request.QueryString["LateAttendanceApprovalID"].ToString() != null || Request.QueryString["LateAttendanceApprovalID"].ToString() != "")
{
LateAttendanceApprovalForEdit();
}
}
private void LateAttendanceApprovalForEdit()
{
btnSave = this.Master.FindControl("btnSave") as Button;
if (btnSave.Text != "Update")
{
var LateRepository = new LateAttendanceRepository();
var LateApprovalDto = new LateAttendanceApprovalDto();
LateApprovalDto.LateAttendanceApprovalID = Convert.ToString(Request.QueryString["LateAttendanceApprovalID"]);
LateApprovalDto = LateRepository.LoadLateAttendanceForEdit(LateApprovalDto).AttendanceApproval;
txtApproveDate.Text = Convert.ToString(LateApprovalDto.ApprovalDate);
txtArrivingTime.Text = Convert.ToString(LateApprovalDto.ArrivingTime);
txtRemarks.Text = Convert.ToString(LateApprovalDto.Remarks);
ddlEmployee.SelectedValue = LateApprovalDto.Employee.EmployeeID;
btnSave.Text = "Update";
}
}
private void LoadGridView()
{
LateAttendanceRepository LateRepository = new LateAttendanceRepository();
LateRepository.LoadGridView(grdLateAttendance);
}
void Save_Click(object sender, EventArgs e)
{
if (btnSave.Text == "Update")
{
UpdateLateAttendance();
}
else if (btnSave.Text == "Save")
{
SaveLateAttendance();
}
LoadGridView();
}
private void SaveLateAttendance()
{
var LateRepository = new LateAttendanceRepository();
var LateApprovalDto = new LateAttendanceApprovalDto();
var Company = new CompanyDto();
var employeeDto = new EmployeeDto();
var departmentDto = new DepartmentDto();
LateApprovalDto.LateAttendanceApprovalID = "LT-10";
LateApprovalDto.ApprovalDate = Convert.ToDateTime(txtApproveDate.Text);
LateApprovalDto.ArrivingTime = Convert.ToDateTime(txtArrivingTime.Text); LateRepository.AddLateAttendance(LateApprovalDto);
}
When i insert data then create this exception"Object reference not set to an instance of an object." Error line 81. because btnSave cant find value Update or Save.But i cant understand that.Sorry my poor English.
Source Error:
Line 79: void Save_Click(object sender, EventArgs e)
Line 80: {
Line 81: if (btnSave.Text == "Update")
Line 82: {
Line 83: UpdateAttendance();
请解决问题
pls solute the problem
推荐答案
void Save_Click(object sender, EventArgs e)
{
btnSave = this.Master.FindControl("btnSave") as Button;
if (btnSave.Text == "Update")
{
UpdateLateAttendance();
}
else if (btnSave.Text == "Save")
{
SaveLateAttendance();
}
LoadGridView();
}
这篇关于一键保存和更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!