Click here to Skip to main content
15,905,233 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to read each row and particular cell in each row in gridview.
Posted
Updated 26-Sep-10 21:15pm
v2
Comments
Hiren solanki 27-Sep-10 3:16am    
Edited for readability.
Hiren solanki 27-Sep-10 6:14am    
see my answer with clarification of your doubts.

Probably using this simple snippets with Foreach.

C#
foreach (GridViewRow row in grid.Rows)
        {
            foreach (TableCell cell in row.Cells)
            {
                string cellValue = cell.Text.ToString();
            }

        }


Vote and Accept Answer if it Helped.
 
Share this answer
 
v4
Comments
spandananair 27-Sep-10 6:11am    
can u tel me clearly..
Hiren solanki 27-Sep-10 6:13am    
what is unclear about this. take all the row one by one from all the gridview row and inside row. take one by one cell value for the row. that is the way foreach works.
C#
// gv - GridView
        for (int i = 0; i < gv.Rows.Count; i++)
        {
            for (int j = 0; j < gv.Rows[i].Cells.Count; j++)
            {
                gv.Rows[i].Cells[j].Text
            }
        }
 
Share this answer
 
Comments
spandananair 27-Sep-10 6:11am    
Reason for my vote of 5
Automatic vote of 5 for accepting answer.
spandananair 27-Sep-10 6:18am    
wen i used this code the loop is not going to the second for...can u help me out
Hiren solanki 27-Sep-10 6:50am    
that means, the grid will not have any rows.
AshiqueAhammed 27-Sep-10 7:09am    
This is working for me...
make sure ur gridview contains more than one row...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



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