Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11508

Get Value of a Control from GridView

$
0
0

Hi,

I am current trying to add data from a GridView to a DataTable, as mentioned below

DataTable dt = new DataTable("GridView_Data");
                    foreach (TableCell cell in gvMain.HeaderRow.Cells)
                    {
                        dt.Columns.Add(cell.Text);
                    }
                    foreach (GridViewRow row in gvMain.Rows)
                    {
                        dt.Rows.Add();
                        for (int i = 0; i < row.Cells.Count; i++)
                        {
                            dt.Rows[dt.Rows.Count - 1][i] = row.Cells[i].Text;
                        }
                    }

The row.Cells[i].Text always comes blank as the cell contains asp.net controls, Label and TextBox.  Is it possible to check what type of control is present in that cell and get its value.

There are close to 40 cells/colums in the GridView and each has either a Label or TextBox.  I don’t want use FindControl("String id") for every cell.

Thanks


Regards, Vikram


Viewing all articles
Browse latest Browse all 11508

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>