文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>合并单元格

合并单元格

时间:2010-10-14  来源:程序帝

合并单元格代码
 1     #region 合并单元格 合并某一列2行
2 /// <summary>
3 /// 合并GridView中2列相同信息的行(单元格)
4 /// </summary>
5 /// <param name="GridView1"></param>
6 /// <param name="cols"></param>
7 public static void GroupCol(GridView GridView1, int cols)
8 {
9 if (GridView1.Rows.Count < 1 || cols > GridView1.Rows[0].Cells.Count - 1)
10 {
11 return;
12 }
13 //判断奇数偶数
14 int count;
15 if (GridView1.Rows.Count % 2 == 0)
16 {
17 count = GridView1.Rows.Count;
18 }
19 else
20 {
21 count = GridView1.Rows.Count-1;
22 }
23 //2行并作1行
24 for (int i = 0; i < count; i = i + 2)
25 {
26 TableCell oldTc = GridView1.Rows[i].Cells[cols];
27 TableCell tc = GridView1.Rows[i+1].Cells[cols];
28 tc.Visible = false;
29 oldTc.RowSpan = 2;
30 oldTc.VerticalAlign = VerticalAlign.Middle;
31 }
32 }
33 #endregion

 

删除时一并删除2行
 1     //删除时一并删除2行
2 protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
3 {
4 int i = e.RowIndex;
5 string s1, s2, strSql;
6 if (i + 1 < GridView1.Rows.Count)
7 {
8 s1 = this.GridView1.Rows[i].Cells[1].Text.ToString();
9 s2 = this.GridView1.Rows[i + 1].Cells[1].Text.ToString();
10 strSql = "delete from Page where No='" + s1 + "' Or No='" + s2 + "'";
11 }
12 else
13 {
14 s1 = this.GridView1.Rows[i].Cells[1].Text.ToString();
15 strSql = "delete from Page where No='" + s1 + "'";
16 }
17 SqlConnection sqlcon=new SqlConnection("Data Source=(local);Initial Catalog=peter;Integrated Security=true");
18 sqlcon.Open();
19 SqlCommand sqlcom=new SqlCommand(strSql,sqlcon);
20 sqlcom.ExecuteNonQuery();
21 sqlcon.Close();
22 BindGridView();
23 }

 

绑定数据
 1     //绑定数据
2 private void BindGridView()
3 {
4 SqlConnection sqlcon = new SqlConnection("Data Source=(local);Initial Catalog=peter;Integrated Security=true");
5 string strsql = "select * from page";
6 SqlDataAdapter dp = new SqlDataAdapter(strsql, sqlcon);
7 sqlcon.Open();
8 DataSet ds = new DataSet();
9 dp.Fill(ds, "Delete");
10 this.GridView1.DataSource = ds;
11 this.GridView1.DataBind();
12 sqlcon.Close();
13 GroupCol(this.GridView1, 0);
14 }

 

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载