2014-10-29 26 views
-1

我正在創建一組學生。我在c#asp.net中有一個Gridview.It包含一個項目模板字段label.I有一個dropdownlist,我從中選擇no。我希望在gridview上應用循環,以便當我從dropdownlist中選擇任何整數值時,項目模板字段標籤的值爲...例如 如果我從dropdownlist中選擇3,則循環的工作,因爲它第一次分配的值頂部3名學生,然後移動到最後的GridView,並從底部值分配給頂部3名學生和再從頂部移動等等......從c最後一行的gridview上循環播放#

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 

請幫助我。

+0

粘貼一些代碼更好理解 – 2014-10-29 06:26:41

回答

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

    }