有个范型,里面有一堆字符串,不知道有多少个:List<string> list = new List<string>();
list.Add("1");
list.Add("2");
list.Add("3");
list.Add("4");
list.Add("5");
list.Add("6");
list.Add("7");当设置了每页数量:int pageItemsCount = list.Count;就可以显示出下面的结果:=========================
List Page 11
2
3
4
5
6
7
=========================假如每页数量是:pageItemsCount = 3;就会出现下面的结果:=========================
List Page 11
2
3List Page 24
5
6List Page 37
=========================请问这个程序该怎么写?谢谢。

解决方案 »

  1.   

    啥东西数组还有 PAGE???放到 gridview 里面 设置属性,,啥都不用你做!或 写个 循环 去取
      

  2.   

    int pagecount = (int)Math.Floor(list.count/pageItemsCount ) + 1  就是你的页数啦。每页输出 pageItemsCount 个,至到结束。大概可以这样写:
    for(int i = 0;i < list.count;i++)
    {
    for(int j = 0 ; j < pagecount;j++)
    {
    if((j+i)> list.count) break;
    if(j == 0)  printOut("新页");
    printOut(list[j+i]);
    i++;}}
      

  3.   

    不知道这样是不是你说的意思。
    如果是最好,如果不是仅供参考!using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;namespace ListTest
    {
        class Program
        {
            static void Main(string[] args)
            {
                List<String> list = new List<string>();            for (int i = 1; i <= 9; i++)
                {
                    list.Add(i.ToString());
                }            int intPageCount = 3;            Test(list, intPageCount);            Console.Read();
            }        public static void Test(List<string> list, int intPageCount)
            {            try
                {
                    Console.WriteLine("=========================");                if (intPageCount == list.Count)
                    {
                        Console.WriteLine("List Page 1");                    //intPageCount == list.Count
                        foreach (string strValue in list)
                        {
                            Console.WriteLine(strValue);
                        }
                    }
                    else
                    {
                        int intModel = 0;
                        int intValue = 0;                    for (int j = 0; j < list.Count; j++)
                        {
                            intValue = j / intPageCount;
                            intModel = j % intPageCount;                        if (intModel == 0)
                            {
                                Console.WriteLine("List Page" + (intValue + 1).ToString());
                            }                        Console.WriteLine(list[j].ToString());
                        }
                    }                Console.WriteLine("=========================");
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
    }
      

  4.   


    不好意思,上面写错啦,改了一下,应该可以啦,自己测试下。
    for(int i=0;i< pageCount;i++)
    {
        printOut("新页");
        for(int j=0 ; j< pageItemsCount;j++)
          {
               if((j+i*pageItemsCount)> list.count)  break;             printOut(list[j+i*pageItemsCount]);
          }}
      

  5.   


    private void button1_Click(object sender, EventArgs e)
    {
        List<string> list = new List<string>();
        list.Add("1");
        list.Add("2");
        list.Add("3");
        list.Add("4");
        list.Add("5");
        list.Add("6");
        list.Add("7");    int num=3;
        StringBuilder sb = new StringBuilder();
        for (int i = 1; i <= list.Count; i++)
        {
            if (i % num == 1) sb.Append("\r\nList Page " + (i / num+1));
            sb.Append("\r\n"+list[i-1]);
        }
        MessageBox.Show(sb.ToString());
    }
      

  6.   

     List<string> list = new List<string>();
                list.Add("1");
                list.Add("2");
                list.Add("3");
                list.Add("4");
                list.Add("5");
                list.Add("6");
                list.Add("7");            int pageItemsCount = list.Count;
                pageItemsCount = 3;
                int num = 0, count = 0, numcount = 0;
                for (int i = 1; i < list.Count+1;i++)
                {
                    if (num % pageItemsCount == 0)
                    {                    Console.WriteLine("第" + (count + 1).ToString() + "页:");
                        
                        num = count;
                    }                while (numcount < pageItemsCount)
                    {
                        if ((Convert.ToInt32((i - 1) / pageItemsCount) == num)&& i<list.Count +1)
                        {
                            Console.WriteLine(list[i - 1]);
                        }
                        
                        numcount++;
                        i++;
                    }
                    num = 0;
                    num=num + pageItemsCount;
                    i--;
                    numcount = 0;
                    count++;
                }