Click here to Skip to main content
Sign Up to vote bad
good
See more: ASP.NETGridview
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:48
Edited 26 Sep '12 - 21:12

Comments
Abhijit Parab - 27 Sep '12 - 2:49
can u explain the senario in detail?
Ankur\m/ - 27 Sep '12 - 3:13
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 - 27 Sep '12 - 2:52
when i click any checkbox..then this checkbox is shows checked
Ankur\m/ - 27 Sep '12 - 3:12
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 - 27 Sep '12 - 2:52
it does'nt matter page reload
Rashid Choudhary - 27 Sep '12 - 2:53
when i reload the page or reopen the page the checkbox is show already checked
Tejas Vaishnav - 27 Sep '12 - 3:04
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 - 27 Sep '12 - 3:12
state is saved

1 solution

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
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 443
1 Arun Vasu 381
2 OriginalGriff 345
3 Maciej Los 191
4 Aarti Meswania 190
0 Sergey Alexandrovich Kryukov 9,755
1 OriginalGriff 7,559
2 CPallini 4,018
3 Rohan Leuva 3,362
4 Maciej Los 2,951


Advertise | Privacy | Mobile
Web02 | 2.6.130523.1 | Last Updated 27 Sep 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid