469,626 Members | 1,369 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,626 developers. It's quick & easy.

How to get subset of rows displayed in current page of DataGrid?

I have a datagrid in my web control class that I am trying to get the current
rows displayed for. I have enabled paging on the datagrid so if the user is
currently on page 3 of 8, and if I have allowed for the table to show only 5
rows at a time, for example, I want to get the 5 rows that are displayed on
page 3 of 8. How do I do this???? Thanks!
Nov 17 '05 #1
3 2081
"Carolyn Vo" wrote:
I have a datagrid in my web control class that I am trying to get the current
rows displayed for. I have enabled paging on the datagrid so if the user is
currently on page 3 of 8, and if I have allowed for the table to show only 5
rows at a time, for example, I want to get the 5 rows that are displayed on
page 3 of 8. How do I do this???? Thanks!


Hi Carolyn,

I think this post is better suited for
microsoft.public.dotnet.framewirk.aspnet

I have not clearly understood your problem but i guess you want to retrieve
the rows of a DataGrid which are displayed on the current page of datagrid.

If this is the problem, than i say this is not a problem as when you check
your datagrid on post back your datagrid will be having only those rows which
are displayed on the current page. As viewstate holds only the current page
of the datagrid not the entire datagrid.

Also your datagrid may be getting modified if you are calling DataBind()
again on postbacks, before processing the subset of rows you are interested
in.

This code snippet will give you better idea on how to select rows from
datagrid:
<CODE>

lblList.Text = "";
foreach(DataGridItem item in grdEmployee.Items)
{
if( item.ItemType == ListItemType.Item || item.ItemType ==
ListItemType.AlternatingItem)
// this is the row you are interested in, do your processing
lblList.Text += item.Cells[0].Text + " | " + item.Cells[1].Text + "<br>";
}

</CODE>

--
Cheers,
Rahul Anand
Nov 17 '05 #2
Hi Rahul,

Thanks for the post. I am trying to get the list of rows that will be
displayed in the page actually so that I can get the first row in the list
and set it to be "selected" in the list when the page comes up. Even if the
user paginates or sorts, when the page comes back I want the current subset
of rows shown to have the first row selected in the list so that its details
can be shown at the bottom of my page. So I need to know what the first item
is in the list to be shown in the datagrid BEFORE a postback is performed.
Does that help?

Carolyn
Nov 17 '05 #3
Hi Carolyn,

As I suggested in the last reply, you can get the first DataGridItem from
your DataGrid and use it to retrieve the row values. You may add some primary
key value as first column in your datagrid, on postback use this field to
show the detals of selected row i.e. first row initially.

In the code where you bind your datagrid with data source, retrieve the
first DataGridItem after binding, this will give you the row for which you
can show the details.

One thing more, if you want to handle the events server side then tha code
must *postback* and only after a postback occurrs you will get the control to
execute your code. Only thing you can control, in this case, is *sequence of
actions*. So, just check for the first item in datagrid when it is bound with
datasource.

If you are still facing problem then post some code example which will
clarify your problem and we can suggest more specific solution.

Hope it will solve your problem.

--
Cheers,
Rahul Anand

"Carolyn Vo" wrote:
Hi Rahul,

Thanks for the post. I am trying to get the list of rows that will be
displayed in the page actually so that I can get the first row in the list
and set it to be "selected" in the list when the page comes up. Even if the
user paginates or sorts, when the page comes back I want the current subset
of rows shown to have the first row selected in the list so that its details
can be shown at the bottom of my page. So I need to know what the first item
is in the list to be shown in the datagrid BEFORE a postback is performed.
Does that help?

Carolyn

Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Mario Vargas | last post: by
1 post views Thread by Diva | last post: by
3 posts views Thread by Jim Heavey | last post: by
2 posts views Thread by The Colonel | last post: by
reply views Thread by rn5a | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.