473,606 Members | 2,101 Online
Bytes | Software Development & Data Engineering Community
+ 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 2254
"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.publi c.dotnet.framew irk.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(DataGri dItem item in grdEmployee.Ite ms)
{
if( item.ItemType == ListItemType.It em || item.ItemType ==
ListItemType.Al ternatingItem)
// 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
3744
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 total number of rows in all the pages? Changing the current page and executing teh Databind() method? Is there another way without having to query the DB again?
1
2250
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, description from page where docid = 1). Any help would be greatly appreciated... because this datagrid thing is kicking my ass. Thank you,
1
5381
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 datagrid. Using the items collection just gives me the 5 rows that are displayed on the screen. Is there any way of looping through all the rows in the grid?
3
4867
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 the best method? Do you have a sample of how to do this?
1
3271
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 days of struggling, I figure asking you all (the experts) will keep me from going down some dark and dangerous road. The project I have is a fairly simple one, in theory anyway. The gist is to create a page where the user enters an IDNumber,...
2
1771
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 able to show the first 5 rows, a button will then allow the user to 'show all records'. Although I've used a DataView before, I am unsure how this can be of use when I need to restrict the number of rows. I am aware of the RowFilter property,...
2
1169
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> Public Sub btnExport_OnClick(ByVal sender As Object, ByVal e As EventArgs)
3
32258
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 datatable without having to loop through each column in the datagridview? Or is there a way to retrieve the rows from the original datatable filtered by the dataview into a separate table? I only want to copy the rows from the main table that...
0
1791
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 checks the rows 2, 4, 6, 8 & 10. When he clicks the Button, the page posts & the next page displays only 5 rows i.e. row 1, 3, 5, 7 & 9. The checked rows are populated in a ViewState variable & will have values like 2, 4, 6, 8, 10, (note that there...
0
7942
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8433
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
6761
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5963
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5461
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3922
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2443
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 we have to send another system
1
1550
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1287
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.