From: JB on
Hello Community

I have a Gridview.

The Gridview already uses the SelectedRow command to allowusers to
select each row and cell in the Gridview. Therefore the user can select any
row that they want.

The problem is that I need to write code that will do these things in the
order of:

1-Go to the first row in the Gridview
2-Retrieve the value from each cell
3-Store the value of each cell value in a variable

This fails:

for (int i = 1; i < gridview.Rows.Count; i++)

{
vlName = gview.Rows[i].Cells[1].Text;
vfname = gview.Rows[i].Cells[2].Text;
}

The above fails because unless a row is first selected in the Gridview, it
doesn't recognize a row in the Gridview.

If it is possible, what is the code to retrieve each row and its cells from
a Gridview programmatically without first selecting a row in the Gridview?

Thanks
Jeff
--
JB

From: Mr. Arnold on
JB wrote:
> Hello Community
>
> I have a Gridview.
>
> The Gridview already uses the SelectedRow command to allowusers to
> select each row and cell in the Gridview. Therefore the user can select any
> row that they want.
>
> The problem is that I need to write code that will do these things in the
> order of:
>
> 1-Go to the first row in the Gridview
> 2-Retrieve the value from each cell
> 3-Store the value of each cell value in a variable
>
> This fails:
>
> for (int i = 1; i < gridview.Rows.Count; i++)
>
> {
> vlName = gview.Rows[i].Cells[1].Text;
> vfname = gview.Rows[i].Cells[2].Text;
> }
>
> The above fails because unless a row is first selected in the Gridview, it
> doesn't recognize a row in the Gridview.
>
> If it is possible, what is the code to retrieve each row and its cells from
> a Gridview programmatically without first selecting a row in the Gridview?
>
> Thanks
> Jeff


It's in VB, but you should be able to figure it out using a foreach in
C#. It's the same thing in VB or C#.

http://forums.asp.net/t/1219338.aspx

But like the person has replied, you can only access the rows in the
grid that have been rendered on the page.