-2

I am creating groups of students .I have a Gridview in c# asp.net.It contain one item template field label.I have one dropdownlist from which i am selecting no. of groups i want to made.I want to apply loop on the gridview in such a way that when I select any integer value from dropdownlist the the item template field label get value as....example If I select 3 from dropdownlist then loop work as it first assign value to top 3 students and then move to last of gridview and assign value from bottom to top 3 STUDENTS and again move from top and so on......

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

Please help me.

Dgan
  • 10,077
  • 1
  • 29
  • 51

1 Answers1

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

    }