gridview中的行在更新时不会从现有行替换

时间:2013-07-18 06:49:57

标签: c# asp.net gridview hyperlink

我目前正致力于员工休假管理。管理器有2个网格视图,显示由特定员工应用的叶子,其中包含ull离开详细信息。 GridView中有“状态”列,其中显示了应用“离开”后的“待处理”。一旦管理员登录并点击更新列,这是一个超级链接,他将重定向到另一个页面,显示休假的详细信息,他可以接受或拒绝休假。一旦他执行了这两个中的任何一个,gridview将获得更新的设置状态=已接受或被拒绝。

在另一个用于Employee的gridview中,显示他/她已应用的所有叶子。即使网格视图已经获得状态,一旦他应用它将显示待定,一旦经理接受/拒绝,它将分别显示。

员工网格视图中也有超链接列,当他点击它时,他将被重定向到另一个页面,显示他已经应用的休假的详细信息,并且它有一个重新申请休假的按钮。

此重新申请仅限于被拒绝或处于待定状态的请假。

问题在于员工重新申请时可能是通过编辑详细信息或使用相同的详细信息来拒绝离开员工的GridView获得更新,但它不会替换为他已重新应用的特定已拒绝行。这将需要新的请假申请。我需要将Rejected Leave请求替换为ReApplied 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>" + "&nbsp; has requested" + "<b>" + "&nbsp;" + LblTypeofLeave.Text + "</b>" + "&nbsp;for" + "<b>" + "&nbsp;" + TxtNumofDays.Text + "&nbsp;" + "</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的行DataBound代码

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();
        }
    }

1 个答案:

答案 0 :(得分:1)

将代码放入行数据绑定

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;
        }