Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All,

I got a gridview which consists of hyperlink in last column upon clicking that it will redirect to another page showing the particular row values in assigned textbox and labels. and there is a reapply button in the page which allows to re aply the leave which is rejected. I have written stored procedure for Updating the grid view and passed it to reaply button what i need is once i press reaply button gridview should update where the particular row which is rejected and should display it as pending status. I got LeaveID as identity column and im retrivin values by using that.

Please help me how to write Row Updating code for this..

code for Button ReApply
C#
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 " + Session["Manager"].ToString() + ",<br /><br />";
        message.Body += "" + Session["EmpName"].ToString() + "" + "  has requested" + "" + " " + LblTypeofLeave.Text + "" + " for" + "" + " " + TxtNumofDays.Text + " " + "<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 = "";
    }


code for GridView
C#
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();
        }
    }


code for Stored Procedure
C#
public int UpdateGrdLeaveHistory(MTMSDTO M)
       {
           DBAccess db = new DBAccess();
           SqlParameter objParam = new SqlParameter("@LeaveID", M.LeaveID);
           objParam.Direction = ParameterDirection.Input;
           objParam.Size = 50;

           db.Parameters.Add(new SqlParameter("@Status", M.@Status));
           db.Parameters.Add(new SqlParameter("@TypeofLeave ", M.TypeofLeave));
           db.Parameters.Add(new SqlParameter("@BeginDate", M.BeginDate));
           db.Parameters.Add(new SqlParameter("@EndDate", M.EndDate));
           db.Parameters.Add(new SqlParameter("@Description", M.Description));
           db.Parameters.Add(new SqlParameter("@NumofDays", M.NumofDays));

           db.Parameters.Add(objParam);

           int retval = db.ExecuteNonQuery("UpdateGrdLeaveHistory");

           if (retval >= 1)
           {
               int i = 0;
               return i;
           }
           else
           {
               return -1;
           }
       }


here is Stored Procedure
SQL
ALTER PROCEDURE [dbo].[UpdateGrdLeaveHistory]

@LeaveID int,
@Status nvarchar(50),
@TypeofLeave nvarchar(50),
@Description nvarchar(50),
@BeginDate date,
@EndDate date,
@NumofDays int

AS


Update dbo.LeaveApply

Set 

TypeofLeave = @TypeofLeave,
NumofDays = @NumofDays,
BeginDate = @BeginDate,
EndDate = @EndDate,
Description = @Description,
Status = @Status

Where LeaveID = @LeaveID ;
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900