473,471 Members | 4,648 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 2246
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mario Vargas | last post by:
Hi, I have a datagrid which has many pages (10 rows per page) and when I loop through the rows, I only get 10 rows (the rows that are currently showed in the current page) How can I get the...
1
by: J | last post by:
This works well for binding a Dataset (created from an XML file) to a DataGrid for the entire 'page' table. However I would like to only grab a few rows from the 'page' table (like: select id,...
1
by: Diva | last post by:
Hi, I have a data grid in my application. It has 20 rows and I have set the page size as 5. I have a Submit button on my form and when I click on Submit, I need to loop through the rows in the...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
1
by: Andrew | last post by:
Hey all, I am very new to ASP.Net (and .Net in general), but that isn't stopping the boss from wanting to begin new projects in it. This latest project has me kinda stumped and after a couple...
2
by: wh1974 | last post by:
I have a DataTable that I'm binding to a DataList control on my web page. I want to be able to restrict the number of rows that are initially displayed from the DataTable. For example I want to be...
2
by: The Colonel | last post by:
Man this export was easy to setup, but it only exports the current page. Any way to get it to export ALL rows? I tried playing with the PageSize before exporting, but no luck. <snip> ...
3
by: Rich | last post by:
Hello, I am populating a datagridview from a datatable and filtering the number of rows with a dataview object. Is there a way to retrieve the rows displayed by the datagridview into a separate...
0
by: rn5a | last post by:
All the rows in a DataGrid are accompanied by a CheckBox. When a user checks the rows & clicks a Button, the checked rows get deleted. For e.g. assume that the DataGrid displays 10 rows. A user...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.