更新时,网格视图中的行不会替换现有行
本文关键字:替换 网格 视图 更新 | 更新日期: 2023-09-27 18:23:54
我目前从事员工休假管理工作。有两个网格视图,一个用于经理,显示特定员工申请的休假,其中包含全部休假详细信息。GridView中有一个状态列,一旦申请休假,就会显示"挂起"。一旦经理登录并点击"更新"列(这是一个超链接),他将重定向到另一个显示休假详细信息的页面,他可以接受或拒绝休假。一旦他完成了这两项中的任何一项,gridview将从Pending中获得更新的设置状态=已接受或已拒绝。
在另一个针对员工的网格视图中,显示了他/她申请的所有假期。即使是网格视图也有状态,一旦他应用,它将显示Pending,而一旦Manager接受/拒绝,它将分别显示两者之一。
员工网格视图中也有超链接列,当他点击时,他将被重定向到另一个页面,显示他申请的休假的详细信息,并且该页面上有一个重新申请休假的按钮。
此重新申请仅适用于被拒绝或处于挂起状态的休假。
问题是,当员工重新申请时,可能是通过编辑详细信息或使用与"已拒绝休假"相同的详细信息。员工的"已拒绝假期"网格视图会更新,但不会被他重新申请的特定"已拒绝"行取代。它将接受新的休假申请。我需要用ReApplied Leave Request将状态从Rejected设置为Pending来替换Rejected Leave Request。
抱歉或是发了很长的帖子,但我想解释一下整个场景。裸着这个。:)
ReAply 的cs代码
protected void BtnReApply_Click(object sender, EventArgs e)
{
MTMSDTO objc = new MTMSDTO();
int Flag = 0;
LblLoggedInUser.Text = Session["EmpName"].ToString();
objc.LoggedInUser = LblLoggedInUser.Text;
objc.TypeofLeave = LblTypeofLeave.Text;
string date;
date = Convert.ToDateTime(TxtBeginDate.Text).ToString("dd/MM/yyyy");
DateTime dt = new DateTime();
dt = Convert.ToDateTime(date);
objc.BeginDate = dt;
objc.EndDate = Convert.ToDateTime(TxtEndDate.Text);
objc.Description = TxtDescription.Text;
objc.NumofDays = Convert.ToInt32(TxtNumofDays.Text);
objc.Status = LblStatus.Text;
int X = obj.InsertLeave(objc);
{
if (X >= 0)
{
Flag = 1;
}
else
{
Flag = 0;
}
}
if (Flag == 1)
{
LblSuccess.Visible = true;
LblSuccess.Text = "Data Added Successfully and Leave Application Succesfully Sent";
}
else
{
LblErr.Visible = true;
LblErr.Text = "Failed To Add Data and Send Leave Request!!!";
}
MailMessage message = new MailMessage();
message.To.Add("");
message.Subject = "Leave Request";
message.From = new MailAddress("");
message.IsBodyHtml = true;
LblLoggedInUser.Text = Session["EmpName"].ToString();
objc.LoggedInUser = LblLoggedInUser.Text;
TxtManager.Text = Session["Manager"].ToString();
objc.Manager = TxtManager.Text;
objc.TypeofLeave = LblTypeofLeave.Text;
objc.NumofDays = Convert.ToInt32(TxtNumofDays.Text.Trim());
message.Body = "<span style = font-family:Arial,font-size:10pt>";
message.Body += "Hello <b>" + Session["Manager"].ToString() + "</b>,<br /><br />";
message.Body += "<b>" + Session["EmpName"].ToString() + "</b>" + " has requested" + "<b>" + " " + LblTypeofLeave.Text + "</b>" + " for" + "<b>" + " " + TxtNumofDays.Text + " " + "</b><br />";
message.Body += "day/days, kindly login to the portal to Accept or Reject it";
message.Body += "<br />";
message.Body += "<br />";
message.Body += "Thank You.<br />";
message.Body += "</span>";
SmtpClient smtp = new SmtpClient("");
smtp.Send(message);
LblTypeofLeave.Text = "";
TxtBeginDate.Text = "";
TxtEndDate.Text = "";
TxtDescription.Text = "";
TxtNumofDays.Text = "";
LblStatus.Text = "";
}
员工GridView 的行数据绑定代码
protected void GridViewLeaveHistory_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
HyperLink ViewDetails = e.Row.FindControl("ViewDetails") as HyperLink;
ViewDetails.NavigateUrl = "ReApply.aspx?LeaveID=" + e.Row.Cells[0].Text;
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
((Label)e.Row.Cells[0].FindControl("Description")).Attributes.Add("style", "word-break:break-all;word-wrap:break-word");
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRow pr = ((DataRowView)e.Row.DataItem).Row;
string status = Convert.ToString(pr["Status"]);
if (status == "Accepted")
{
e.Row.Cells[6].BackColor = System.Drawing.Color.LightBlue;
e.Row.Cells[7].Visible = false;
}
else
{
if(status == "Rejected")
e.Row.Cells[6].BackColor = System.Drawing.Color.Yellow;
if (status == "Pending")
e.Row.Cells[6].BackColor = System.Drawing.Color.LightGray;
}
}
}
这是员工的GridView代码
protected void GrdLeaveHistory()
{
MTMSDTO objc = new MTMSDTO();
{
objc.EmpName = Convert.ToString(Session["EmpName"]);
DataSet GrdLH = obj.GrdLeaveHistory(objc);
DataView GrdLeaveH = new DataView();
GrdLeaveH.Table = GrdLH.Tables[0];
GridViewLeaveHistory.DataSource = GrdLeaveH;
GridViewLeaveHistory.DataBind();
}
}
将代码放入行数据绑定
if (status == "ReApplied")
e.Row.Cells[6].BackColor = System.Drawing.Color.Yellow;
if (status == "Leave Cancellation Requested")
e.Row.Cells[6].BackColor = System.Drawing.Color.LightGray;
在重新应用页面的页面加载中放入此
if (LblStatus.Text == "Rejected")
{
BtnCancelLeave.Visible = false;
}