473,698 Members | 2,411 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

restricting # of rows displayed in a datagrid or datalist

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, but this only allows me to specify a SQL like filter.

Thanks,
Wayne.
Nov 18 '05 #1
2 1778

I think you can be a bit more clever than copying the rows into another table; I would try creating a small helper class that implements IEnumerable and wraps a DataView; just off the top of my head, here something that might get you started:

MyDataList.Data Source = new Show5(MyView);
public class Show5 : IEnumerable
{
DataView m_view;
public Show5(DataView v)
{
m_view = v;
}

public IEnumerator GetEnumerator()
{
return new E5(m_view.GetEn umerator());
}

internal class E5 : IEnumerator {
private IEnumerator m_e;
private int m_cnt = 0;
internal E5(IEnumerator e) {
m_e = e;
}

public object Current {
get { return m_e.Current; }
}

public bool MoveNext() {
if (m_cnt > 5) return false;
m_cnt++;
return m_e.MoveNext();
}

public void Reset() {
m_e.Reset();
m_cnt = 0;
}
}
}

"Greg Hurlman" <ghurlman*AT*sq uaretwo*DOT*net > wrote in message news:33******** *************** ***********@mic rosoft.com...
To do this, you'll want to use the DataTable's DefaultView to set any sorting
or filtering you have, and then create a new DataTable, clone the old
datatable, and then import the first 5 rows from the original DataTable's
dataview, like this:

Dim OriginalView As DataView = OriginalTable.D efaultView
OriginalView.Ro wFilter = "Whatever"
OriginalView.So rt = "Whatever"

Dim NewTable As DataTable = OriginalTable.C lone()
For i As Integer = 1 To 5
NewTable.Import Row(OriginalVie w(i).Row)
Next

MyDataGrid.Data Source = NewTable
MyDataGrid.Data Bind()

"wh1974" wrote:
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, but this only allows me to specify a SQL like filter.

Thanks,
Wayne.


Nov 18 '05 #2
Thanks to both of you for your ideas.

Much appreciated.
Wayne.
Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4567
by: Mike Malter | last post by:
I take it that the only way to add rows to a DataList control is through DataBind? If not, how do I manually add rows to a DataList control? I have searched everywhere and can't find an example anywhere other than through building a DataTable, and then doing a DataBind. Thanks. Mike
0
1214
by: pei_world | last post by:
I am using the following code to configurate my datagrid and load data from my Pocket Access Database. however, I got some more row extra, and it is the number I setted with my object array in my GetData function. the extra rows were filled with my column header.for example, If I have my field=5, the first row is my original data, the rest are filled as my header name. I have check to work flow. it shouldn't filled that header name. I...
3
2261
by: Carolyn Vo | last post by:
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!
1
1733
by: Reddy | last post by:
Hi, I have a html table in which the first two rows would be static data header. The remainder of rows get populated from the database. I want to implement this using a datagrid, datalist or repeater to which I can bind a dataset. The problem which I am facing here is the first two static rows. Any ideas how to implement this. Any pointers to sample code would be great. Thanks
1
5287
by: Craig Banks | last post by:
If a row of data in a dataset has a lot of columns the row displaying the data in a datagrid will run way off the screen. What I'd like to do is display a row of data over several datagrid rows so the user doesn't have to scroll horizontally. Essentially, I want to wrap a datagrid row (not text in individual columns) with as much control as possible. Make sense? While this seems simple enough on the surface, I can't figure out how to do...
3
6404
by: anon | last post by:
Hi All, I would like to make a datalist which takes new information by allowing users(with some button or link) to add new rows to a datalist with some information and save the information.....is it even possible to do with a datalist or shud i use only a datagrid... any ideas or online samples/URLS would be greatly appreicated ... thanks for ur time Ben
0
1698
by: Chris | last post by:
I've been searching all over and think I am close, but keep getting the error "Index out of range" when trying to reference a nested datagrid when an OnEditCommand event is raised. When the OnEditCommand event is raised, I try to do the following: 1. Find the selected datalist item in which the nested datagrid raised the event. (by calling getDataGridReference and returning the DataList's selectedIndex)
2
2622
by: Brett Romero | last post by:
I have a CustomDataGrid that inherits DataGrid. I use the filter below via a context menu, which works fine. ( ( DataTable ) this.DataSource ).DefaultView.RowFilter = filterexpress; The above gives me narrowed results via a right click on a grid cell. I filter on the cell value. I'd like to click another cell and filter again. For example, I start with 100 rows. I filter as above and get 50 rows. Now I want to filter on another...
0
1794
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
8685
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8612
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
8880
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7743
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
6532
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
5869
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();...
1
3053
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
2
2342
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2008
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.