Home > DeveloperSection > Forums > Filling DataTable from GridView in C#
Mark Devid
Mark Devid

Total Post:101

Posted on    February-03-2014 12:05 AM

 C# C# 

 1 Reply(s)
 2041  View(s)
Rate this:

How can I fill DataTable from GridView in ASP.NET?

Pravesh Singh

Total Post:411

Posted on    February-03-2014 12:58 AM

Hi Mark,

I solved like this

           if (myGridView.Rows.Count > 0)


                var dt = new DataTable();

                dt.Columns.Add("Column1", typeof(string));

                dt.Columns.Add("Column2", typeof(Int64));

                dt.Columns.Add("Column3", typeof(string));

                foreach (GridViewRow row in gd_endYearSchool.Rows)


                    var id = row.Cells[1].Text;

         //for find textbox

          var tb1 = row.Cells[2].FindControl("tbNr") as TextBox;

                    int nrord = 0;

                    if (tb1 != null)


                        var ord = tb1.Text;

                        if (!Int64.TryParse(ord, out nrord))


                            nrord = 0;



                    var text=row.Cell[3].text;




Don't want to miss updates? Please click the below button!

Follow MindStick