By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,212 Members | 2,209 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,212 IT Pros & Developers. It's quick & easy.

Gridview dynamic pagesize

P: n/a
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.DataSource = customer;
int groupId,groupRowId,count;

groupId = 1;
for (int i = 0; i < gridCustomer.Rows.Count; i++)
{
GridViewRow row = gridCustomer.Rows[i];
Label lblGroupId =
(Label)row.FindControl("GroupId");
groupRowId = Convert.ToInt32(lblGroupId.Text);

if (groupId == groupRowId)
{
count = count + 1;
}
else
{
gridCustomer.PageSize = count;
count = 0;
groupId = groupId + 1;
}
}
gridCustomer.DataBind();

Jun 27 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On May 6, 1:38*pm, icanhel...@gmail.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.DataSource = customer;
int groupId,groupRowId,count;

* * * * * * * * groupId = 1;
* * * * * * * * for (int i = 0; i < gridCustomer.Rows.Count; i++)
* * * * * * * * {
* * * * * * * * * * GridViewRow row = gridCustomer.Rows[i];
* * * * * * * * * * Label lblGroupId =
(Label)row.FindControl("GroupId");
* * * * * * * * * * groupRowId = Convert.ToInt32(lblGroupId.Text);

* * * * * * * * * * if (groupId == groupRowId)
* * * * * * * * * * {
* * * * * * * * * * * *count = count + 1;
* * * * * * * * * * }
* * * * * * * * * * else
* * * * * * * * * * {
* * * * * * * * * * * * gridCustomer.PageSize = count;
* * * * * * * * * * * * count = 0;
* * * * * * * * * * * * groupId = groupId + 1;
* * * * * * * * * * }
* * * * * * * * }
*gridCustomer.DataBind();
Hi,

You have to implement an enumerator:

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

while( startIndex< customer.Couint){

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

yield break;

}
Jun 27 '08 #2

P: n/a
I get an error at yield return customer[startIndex+
+]; ...can't convert customer to system.data.datarow. Also where will
I say gridCustomer.DataBind in this code.
IEnumerable<DataRow>PageItems()
{
int startIndex = 0;
CustomersManager manager = new CustomersManager();
List<Customerscustomer =
manager.GetDuplicateCustomers();
gridCustomer.DataSource = 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 discussion thread is closed

Replies have been disabled for this discussion.