How to programmatically retrieve all rows and cells in Gridview

J

JB

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.Cells[1].Text;
vfname = gview.Rows.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
 
M

Mr. Arnold

JB said:
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.Cells[1].Text;
vfname = gview.Rows.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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top