473,800 Members | 2,413 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Gridview dynamic pagesize

I would like to assign dynamic pagesize to a gridview called
gridCustomer. The customer data is a List with a column called
groupId . When a new groupid is encountered I would like to display
data in a new page. The code doesn't seem to work. Can you please
help.

gridCustomer.Da taSource = customer;
int groupId,groupRo wId,count;

groupId = 1;
for (int i = 0; i < gridCustomer.Ro ws.Count; i++)
{
GridViewRow row = gridCustomer.Ro ws[i];
Label lblGroupId =
(Label)row.Find Control("GroupI d");
groupRowId = Convert.ToInt32 (lblGroupId.Tex t);

if (groupId == groupRowId)
{
count = count + 1;
}
else
{
gridCustomer.Pa geSize = count;
count = 0;
groupId = groupId + 1;
}
}
gridCustomer.Da taBind();

Jun 27 '08 #1
2 2752
On May 6, 1:38*pm, icanhel...@gmai l.com wrote:
I would like to assign dynamic pagesize to a gridview called
gridCustomer. The customer data is a List with a column called
groupId . When a new groupid is encountered I would like to display
data in a new page. The code doesn't seem to work. Can you please
help.

gridCustomer.Da taSource = customer;
int groupId,groupRo wId,count;

* * * * * * * * groupId = 1;
* * * * * * * * for (int i = 0; i < gridCustomer.Ro ws.Count; i++)
* * * * * * * * {
* * * * * * * * * * GridViewRow row = gridCustomer.Ro ws[i];
* * * * * * * * * * Label lblGroupId =
(Label)row.Find Control("GroupI d");
* * * * * * * * * * groupRowId = Convert.ToInt32 (lblGroupId.Tex t);

* * * * * * * * * * if (groupId == groupRowId)
* * * * * * * * * * {
* * * * * * * * * * * *count = count + 1;
* * * * * * * * * * }
* * * * * * * * * * else
* * * * * * * * * * {
* * * * * * * * * * * * gridCustomer.Pa geSize = count;
* * * * * * * * * * * * count = 0;
* * * * * * * * * * * * groupId = groupId + 1;
* * * * * * * * * * }
* * * * * * * * }
*gridCustomer.D ataBind();
Hi,

You have to implement an enumerator:

string currentId; = customer[0].Id;
int startIndex=0;
IEnumerable<Dat aRow PageItems() {

while( startIndex< customer.Couint ){

if ( customer[startIndex].Id == currentId)
yield return customer[startIndex++];
else
yield break;
}

yield break;

}
Jun 27 '08 #2
I get an error at yield return customer[startIndex+
+]; ...can't convert customer to system.data.dat arow. Also where will
I say gridCustomer.Da taBind in this code.
IEnumerable<Dat aRow>PageItems( )
{
int startIndex = 0;
CustomersManage r manager = new CustomersManage r();
List<Customersc ustomer =
manager.GetDupl icateCustomers( );
gridCustomer.Da taSource = customer;
int currentId = customer[0].GroupId;
while (startIndex < customer.Count)
{
if ( customer[startIndex].GroupId == currentId)
{
yield return customer[startIndex++];
}
else
{
yield break;
}
yield break;
}
}

Jun 27 '08 #3

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

Similar topics

2
6552
by: Robert Smith jr. | last post by:
Hello, Please pardon my newbie question ... I am building an ASP.NET page that displays a recordset with a Delete statement enabled (this all works fine). I want to Insert the current row *that is going to be deleted* into another table, before the original data is deleted. I am trying to use the RowDeleting method to call an Update or Insert
7
5475
by: Ken | last post by:
Hi All - I have a filtered GridView. This GridView has a check box in the first column. This check box is used to identify specific rows for delete operations. On the button click event I loop through the filtered GridView to identify the selected rows and assemble some XML to be sent to a stored proc. The problem I have is that when looping through the GridView, it doesn't
10
5310
by: NH | last post by:
I have a girdview with paging enabled. How can I add a message in the footer to say "Viewing records 1-15 of 45" etc Thanks
0
1875
by: jeffmagill | last post by:
Hi Everybody, I'm really hoping that someone can help me out because I have spent too much time on this project already! Basically, I have a DetailsView that handles all the Edits for a GridView - each row has an edit button and clicking on this should trigger that record to be loaded into the DetailsView for editing. The problem is that the record never gets loaded into the DetailsView. Instead, the DetailsView always and only...
4
3745
by: Adam Sandler | last post by:
Hello, Using VWD 2005 here and I want to set the GridView PageSize at runtime. This URL has an example of what I exactly want to do... http://msdn2.microsoft.com/en-US/library/system.web.ui.webcontrols.gridview.pagesize.aspx Public Overridable Property PageSize As Integer Dim instance As GridView Dim value As Integer
8
8539
by: AG | last post by:
ASP.NET 2.0, VS 2005 I have a gridview with paging enabled, bound to an objectdatasource. Both were dropped on to the page and configured via the wizards. Basically working as expected. The gridview's databind method is apparently called when the page is loaded as I have no code calling the databind method. How can I keep the gridview from databinding automatically and control it myself?
5
3009
by: Andrew Robinson | last post by:
I am attempting to better automate a Pager Template within a GridView. I am succesfully skinning a Drop Down List withing my control (the DDL is added to my control). I correctly populate the item list that corresponds with the number of pages, but I am unable to wire up the Selected Index Changed event. Auto PostBack is set to true and the page is posting back when the DDL is selected / chaged, but the event is never being called. Any...
4
2730
by: Don Miller | last post by:
This is a repost of a reproducible problem/bug with GridView with dynamic SQL and binding. Is there a better ASP.NET newsgroup I should post to where MS techs or MVPs take an interest in such problems? Thanks. Here is an example of what I believe is a bug in ASP.NET 2.0 GridView paging without postbacks (or at least not documented how to fix it). Once the GridView is displayed, clicking on any of the paging tools causes the
3
1939
by: Nathan Sokalski | last post by:
I have a GridView control with three columns, all BoundField columns. They all have a HeaderText and DataField property set, and the third one has a DataFormatString property as well. When I run my code, the GridView displays two sets of columns. The first set looks exactly as I would expect. The second set, which should not be there anyway, uses the DataField as the header and does not apply the DataFormatString for the third column. What...
0
9691
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
9551
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
10035
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
9090
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
7580
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
6813
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
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2945
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.