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

Re: Gridview dynamic pagesize by Ignacio

Ignacio
Tue May 06 13:38:35 CDT 2008

On May 6, 1:38=A0pm, 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 =3D customer;
> int groupId,groupRowId,count;
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 groupId =3D 1;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 for (int i =3D 0; i < gridCustomer.Rows.Co=
unt; i++)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 GridViewRow row =3D gridCustomer.R=
ows[i];
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Label lblGroupId =3D
> (Label)row.FindControl("GroupId");
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 groupRowId =3D Convert.ToInt32(lbl=
GroupId.Text);
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (groupId =3D=3D groupRowId)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0count =3D count + 1;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 else
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 gridCustomer.PageSize =3D =
count;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 count =3D 0;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 groupId =3D groupId + 1;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> =A0gridCustomer.DataBind();

Hi,

You have to implement an enumerator:

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

while( startIndex< customer.Couint){

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

yield break;

}

Re: Gridview dynamic pagesize by icanhelp33

icanhelp33
Tue May 06 15:54:07 CDT 2008

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;
}
}