Click here to Skip to main content
15,897,147 members

i am new in asp.net. i have a problem in gridview.

Rashid Choudhary asked:

Open original thread
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
C#
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();

       }
Tags: ASP.NET, Gridview

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



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