【问题标题】:Looping on gridview from last row in c#从c#的最后一行循环gridview
【发布时间】:2014-10-29 06:18:57
【问题描述】:

我正在创建学生组。我在 c# asp.net 中有一个 Gridview。它包含一个项目模板字段标签。我有一个下拉列表,我从中选择否。我想制作的组。我想在gridview上应用循环,这样当我从下拉列表中选择任何整数值时,项目模板字段标签将获得值作为......示例 如果我从下拉列表中选择 3,然后循环工作,因为它首先为前 3 名学生分配值,然后移动到 gridview 的最后一个并从底部到顶部 3 名学生分配值,然后再次从顶部移动等等......

name       groupno.

A             1   
B             2
C             3
D             1
E             2
F             3 
G             1
H             3
I             2
J             1
K             3
L             2
M             1

请帮帮我。

【问题讨论】:

  • 贴一些代码更好理解

标签: c# asp.net gridview itemtemplate


【解决方案1】:
protected void Button1_Click(object sender, EventArgs e)
{
        DataTable dt1;
        DataRow row; 
        dt1 = new DataTable();
        dt1.Columns.Add("GroupNo");
        dt1.Columns.Add("Registration");
        dt1.Columns.Add("Name");
        dt1.Columns.Add("Marks");
        dt1.Columns.Add("Technology");
        dt1.AcceptChanges();
        return dt1;

        int starting = 0, Ending = GridView1.Rows.Count-1, flag = 0, groupsize =5 , Count_Stu = 1;

        for (int i = 0; i <= countvalue; i++)
        {
            if (flag == 0)  // Top To Down
            {
                row = dt1.NewRow();
                row["GroupNo"] = Count_Stu.ToString();
                row["Registration"] = GridView1.Rows[starting].Cells[0].Text;
                row["Name"] = GridView1.Rows[starting].Cells[1].Text;
                row["Marks"] = GridView1.Rows[starting].Cells[2].Text;
                row["Technology"] = GridView1.Rows[starting].Cells[3].Text;
                dt1.Rows.Add(row);
                Count_Stu++;
                starting++;
            }
            else if (flag == 1) // Down To Up
            {
                row = dt1.NewRow();
                row["GroupNo"] = Count_Stu.ToString();
                row["Registration"] = GridView1.Rows[Ending].Cells[0].Text;
                row["Name"] = GridView1.Rows[Ending].Cells[1].Text;
                row["Marks"] = GridView1.Rows[Ending].Cells[2].Text;
                row["Technology"] = GridView1.Rows[Ending].Cells[3].Text;
                dt1.Rows.Add(row);
                Count_Stu++;
                Ending--;
            }

            if (Count_Stu == groupsize+1)   //Reset 
            {
                if (flag == 0)
                    flag = 1;
                else
                    flag = 0;
                Count_Stu = 1;
            }
        }
        GridView2.DataSource = dt1;
        GridView2.DataBind();

    }

【讨论】:

    猜你喜欢
    • 2016-01-08
    • 2020-12-01
    • 2013-08-03
    • 1970-01-01
    • 1970-01-01
    • 2021-06-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多