---
title: "Filling DataTable from GridView in C#"  
description: "Filling DataTable from GridView in C#"  
author: "Mark Devid"  
published: 2014-02-03  
updated: 2014-02-03  
canonical: https://www.mindstick.com/forum/1942/filling-datatable-from-gridview-in-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Filling DataTable from GridView in C#

How can I fill [DataTable](https://www.mindstick.com/blog/195/datatable-in-ado-dot-net) from [GridView](https://www.mindstick.com/articles/873/update-delete-edit-gridview-in-asp-dot-net) in [ASP.NET](https://www.mindstick.com/articles/934/default-folders-available-inside-the-asp-dot-net-application-folder)?

## Replies

### Reply by Pravesh Singh

**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;                   
dt.Rows.Add(id,nrord,text);                }            }
```


---

Original Source: https://www.mindstick.com/forum/1942/filling-datatable-from-gridview-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
