Tuesday, September 6, 2011

Get values of a check box to do a command in for loop


protected void Btn_ApproveChkd_Click(object sender, EventArgs e)
{
try
{
int itemChecked = 0;
foreach (GridViewRow Gitem in grdDispatchGrid.Rows)
{               
CheckBox ChkGrid = (CheckBox)Gitem.FindControl("ChkApprove");
if (ChkGrid.Checked == true)
{
itemChecked = 1;
break;
}
}
if (itemChecked == 1)

{
foreach (GridViewRow Gitem in grdDispatchGrid.Rows)

{                   
int _LeaveId = Convert.ToInt32(grdDispatchGrid.DataKeys[Gitem.RowIndex].Values["leave_id"].ToString());
con.Open();

string Qry = "ReqLeaveApproved";

SqlCommand cmd = new SqlCommand(Qry, con);

cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.Add("@Emp_Id", SqlDbType.NChar);

cmd.Parameters["@Emp_Id"].Value = Session["_EmpId"];

cmd.Parameters.Add("@leave_id", SqlDbType.Int);

cmd.Parameters["@leave_id"].Value = _LeaveId;

cmd.Parameters.Add("@Status", SqlDbType.Int);

cmd.Parameters["@Status"].Value = "2";

cmd.ExecuteNonQuery();

con.Close();

}

Response.Redirect(
"FrmAdminApproval.aspx");

}

else if (itemChecked == 0)

{

}

}

catch (Exception Ex)

{

}

}

No comments:

Post a Comment