Hello,
i made a checkbox templatefield in gridview that let me select the rows wanted ...and i have a button to do something for all rows selected ...my problem is after click button i want unchech all checkbox in gridview ...i wrote this code but not working:
protected void btnPaye_Click(object sender, EventArgs e)
{
//TextBox1.Text = "";
foreach (GridViewRow gvr in gdfacture.Rows)
{
if (gvr.RowType == DataControlRowType.DataRow)
{
CheckBox cb = (CheckBox)(gvr.FindControl("chkSelect"));
decimal taux= Convert.ToDecimal(txttaux.Text);
decimal Prix= Convert.ToDecimal(gvr.Cells[1].Text) ;
decimal RestPaye= ((100 - taux)*Prix)/100 ;
DateTime DatePaiment = Convert.ToDateTime(txtdatepaiment.Text);
if (cb.Checked == true)
{
string constr = ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
con.Open();
SqlCommand cmd = new SqlCommand("UPDATE Facture SET EtatFacture=@strEtatFacture,Taux=@strTaux " +
",RestePaye=@strRestePaye,DatePaiment=@strDatePaiment,NumCheque=@strNumCheque WHERE [IdFacture]='" + Convert.ToInt32(gvr.Cells[0].Text) + "'", con);
cmd.Parameters.AddWithValue("@strEtatFacture", "Payé");
cmd.Parameters.AddWithValue("@strTaux",taux );
cmd.Parameters.AddWithValue("@strRestePaye",RestPaye);
cmd.Parameters.AddWithValue("@strDatePaiment", DatePaiment);
cmd.Parameters.AddWithValue("@strNumCheque", txtcheque.Text);
cmd.ExecuteNonQuery();
con.Close();
LabelRes.Text = "<b> Paiment </b> avec succès.";
//cb.Checked = false; // uncheck checkBox
}
}
}
//empty the fields after insertion
txtdatepaiment.Text = string.Empty;
txtcheque.Text = string.Empty;
txttaux.Text = string.Empty;
foreach (GridViewRow gvrow in gdfacture.Rows)
{
CheckBox chk = (CheckBox)(gvrow.FindControl("chkSelect"));
if (chk.Checked)
{
chk.Checked = false;
}
}
//int RowsCount = gdfacture.Rows.Count;
//for (int i = 0; i < RowsCount; i++)
//{
// CheckBox chkDelete = gdfacture.Rows[i].FindControl("chkSelect") as CheckBox;
// if (chkDelete.Checked == true)
// {
// chkDelete.Checked = false;
// }
//}
gdfacture.DataBind();
btnPaye.Enabled = false;
}