j c

j c

  • NA
  • 45
  • 0

Add checked rows (gridview)to a data table (memory)

Oct 28 2010 5:55 PM

   I am trying to add checked rows's ID in Gridview to a data table ( memory) …so I can use it for other process..

 

But it only add the ID from the last checked row in gridview…( for excample, I checked three rows , it only add the last checked rows to a data table) what am I doing wrong? How can I fix this?

 

        protected void LinkButton_AddNewUser_Click(object sender, EventArgs e)

        {

 

            DataTable dt = new DataTable();

         

            dt.Columns.Add("ID");

      

 

            DataRow dataRow;

            dataRow = dt.NewRow();

 

 

            for (int i = 0; i <= GV_NewUser.Rows.Count - 1; i++)

                    foreach (GridViewRow di in GV_NewUser.Rows)

                        {

                            CheckBox chk = (CheckBox)di.FindControl("AddUsers");

                            if (chk != null && chk.Checked)

                            {

                                dataRow["ID"] = di.Cells[0].Text;

                    

                                   dt.Rows.Add(dataRow);

                                                    

 

                            }

                        }

 

 

 

 

            GridView1.DataSource = dt;

            GridView1.DataBind();

 

 

          }

 

 


Answers (1)