//gridview 相同列合并 private void GroupRows(GridView grv) { string[] drs = { "ConferenceStartDate", "ddd" }; int num = 1; for (int j = num - 1; j < grv.Rows.Count - 1; j++) //循环行 { int r = 1; num = 1; GridViewRow gvr = grv.Rows[j];//前一行的单元格 for (int i = j + 1; i < grv.Rows.Count; i++)//下一行 { if (r < 2) { GridViewRow gvrNext = grv.Rows[i]; HiddenField hidpersonname = grv.Rows[j].FindControl("hidpersonname") as HiddenField; HiddenField HidSign = grv.Rows[j].FindControl("HidSign") as HiddenField; HiddenField hidUnitID = grv.Rows[j].FindControl("hidUnitID") as HiddenField; HiddenField Hiduintnum = grv.Rows[j].FindControl("Hiduintnum") as HiddenField; HiddenField hidpersonname1 = grv.Rows[i].FindControl("hidpersonname") as HiddenField; HiddenField HidSign1 = grv.Rows[i].FindControl("HidSign") as HiddenField; HiddenField hidUnitID1 = grv.Rows[i].FindControl("hidUnitID") as HiddenField; HiddenField Hiduintnum1 = grv.Rows[i].FindControl("Hiduintnum") as HiddenField; //Label lID1 = grv.Rows[j].FindControl("lbID" + drs[r].ToString()) as Label; //Label lID2 = grv.Rows[i].FindControl("lbID" + drs[r].ToString()) as Label; //Label l1 = grv.Rows[j].FindControl("lbSign" + drs[r].ToString()) as Label; //Label l2 = grv.Rows[i].FindControl("lbSign" + drs[r].ToString()) as Label; if (hidpersonname.Value == hidpersonname1.Value && HidSign.Value == HidSign1.Value && hidUnitID.Value == hidUnitID1.Value && Hiduintnum.Value == Hiduintnum1.Value) { num += 1; gvrNext.Cells[r + 1].Visible = false; gvr.Cells[r + 1].RowSpan = num; } else { num = 1; break; } } //else //{ // GridViewRow gvrNext = grv.Rows[i]; // Label lID1 = grv.Rows[j].FindControl("lbID" + drs[r].ToString()) as Label; // Label lID2 = grv.Rows[i].FindControl("lbID" + drs[r].ToString()) as Label; // Label l1 = grv.Rows[j].FindControl("lbSign" + drs[r].ToString()) as Label; // Label l2 = grv.Rows[i].FindControl("lbSign" + drs[r].ToString()) as Label; // Label lbWork1 = grv.Rows[j].FindControl("lbWork" + drs[r].ToString()) as Label; // Label lbWork2 = grv.Rows[i].FindControl("lbWork" + drs[r].ToString()) as Label; // if (l1.Text == l2.Text && lID1.Text == lID2.Text && lbWork1.Text == lbWork2.Text) // { // num += 1; // gvrNext.Cells[r + 1].Visible = false; // gvr.Cells[r + 1].RowSpan = num; // } // else // { // num = 1; // break; // } //} //} } } }
原文:http://www.cnblogs.com/wjwei/p/3848269.html