Gridview dynamic pagesize

  • Thread starter Thread starter icanhelp33
  • Start date Start date
I

icanhelp33

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;
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();
 
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;
                    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;

}
 
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<Customers> customer =
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;
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top