Click here to Skip to main content
11,715,425 members (77,875 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET Gridview
i have check boxes in grid view. and i want, when i checked any check box then this
checkbox state is saved.. when we reopen the page this check box is shows checked....
here is my c# code
protected void Grid1_RowUpdating(object sender, GridViewUpdateEventArgs e)
       {
           int i = e.RowIndex;
           int pid = Convert.ToInt32(Grid1.DataKeys[e.RowIndex].Values[0].ToString());
           string uid = Grid1.DataKeys[e.RowIndex].Values[1].ToString();
           Label lbl2 = (Label)Grid1.Rows[i].Cells[5].FindControl("lbl1");
           TextBox txtlbl1 = (TextBox)Grid1.Rows[i].Cells[4].FindControl("txtlbl");
           StringBuilder str = new StringBuilder();
           for (int j = 0; j < Grid1.Rows.Count; j++)
           {
               GridViewRow row = Grid1.Rows[i];
               //CheckBox aa = (row.FindControl("checkbox1") as CheckBox).Checked;
               bool isChecked = ((CheckBox)row.FindControl("checkbox1")).Checked;
               if (isChecked)
               {
                   str.Append(Grid1.Rows[i].Cells[3].Text);
               }
 
           }
           string str1 = txtlbl1.Text;
           SqlCommand cmd = new SqlCommand("update Product_order set Extend_date='" + txtlbl1.Text + "'where P_id=" + pid , con);
           cmd.ExecuteNonQuery();
           Grid1.EditIndex = -1;
           buildgrid();
           string BID = auto_ID();
           Session["back_office"] = BID;
           cmd = new SqlCommand("insert into Backofc_master (B_ID) values ('" + BID + "') ", con);
           cmd.ExecuteNonQuery();
 
       }
Posted 26-Sep-12 20:48pm
Edited 26-Sep-12 21:12pm
v5
Comments
Abhijit Parab at 27-Sep-12 2:49am
   
can u explain the senario in detail?
Ankur\m/ at 27-Sep-12 3:13am
   
OP wrote:
i) when i click any checkbox..then this checkbox is shows checked
ii) it does'nt matter page reload
iii) when i reload the page or reopen the page the checkbox is show already checked
Rashid Choudhary at 27-Sep-12 2:52am
   
when i click any checkbox..then this checkbox is shows checked
Ankur\m/ at 27-Sep-12 3:12am
   
Use the reply link against the comment, as I did or the poster you are replying to won't be notified of your comment.
Rashid Choudhary at 27-Sep-12 2:52am
   
it does'nt matter page reload
Rashid Choudhary at 27-Sep-12 2:53am
   
when i reload the page or reopen the page the checkbox is show already checked
Tejas Vaishnav at 27-Sep-12 3:04am
   
so what you want you need to unchecked that check box while the page is re-open or you need to say like if I save the state of check box as saved then while assessing that page again then the previously saved state will remains save as saved state(checked/unchecked). Please be more specific to your question so other can understand what you need to ask.
Rashid Choudhary at 27-Sep-12 3:12am
   
state is saved

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

i'm not sure.. try clearing viewstate or controlstate value
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 485
1 Richard MacCutchan 275
2 Maciej Los 259
3 ManasKumarM 155
4 Frankie-C 125
0 Sergey Alexandrovich Kryukov 785
1 CHill60 415
2 Richard MacCutchan 405
3 Maciej Los 389
4 OriginalGriff 320


Advertise | Privacy | Mobile
Web01 | 2.8.150901.1 | Last Updated 27 Sep 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100