Code
1 protected void Button1_Click(object sender, EventArgs e)
2 {
3 Response.Clear();
4 this.GridView1.Columns[0].Visible = false; //第一列是复选框,将其屏蔽
5 this.GridView1.FooterRow.Visible = false; //屏蔽脚注
6 for (int i = 0; i < this.GridView1.Rows.Count; i++)
7 {
8 if (!((CheckBox)this.GridView1.Rows[i].FindControl("CheckBox2")).Checked)
9 {
10 this.GridView1.Rows[i].Visible = false; //如果该行未被选中,屏蔽!
11 }
12 }
13
14 this.GridView1.BottomPagerRow.Visible = false; //把页数,也屏蔽掉 就是 1 2 3 4页
15
16
17 Response.Buffer = true;
18 Response.Charset = "GB2312";
19 Response.AppendHeader("Content-Disposition", "attachment;filename=Exclefile.xls");
20 // 如果设置为 GetEncoding("GB2312");导出的文件将会出现乱码!!!
21 Response.ContentEncoding = System.Text.Encoding.UTF7;
22 Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。
23 System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
24 System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
25 this.GridView1.RenderControl(oHtmlTextWriter);
26 Response.Output.Write(oStringWriter.ToString());
27 Response.Flush();
28 Response.End();
29 }
30//下面这个函数一定要有的,否则会报错.
31 public override void VerifyRenderingInServerForm(Control control)
32 { }
1 protected void Button1_Click(object sender, EventArgs e)
2 {
3 Response.Clear();
4 this.GridView1.Columns[0].Visible = false; //第一列是复选框,将其屏蔽
5 this.GridView1.FooterRow.Visible = false; //屏蔽脚注
6 for (int i = 0; i < this.GridView1.Rows.Count; i++)
7 {
8 if (!((CheckBox)this.GridView1.Rows[i].FindControl("CheckBox2")).Checked)
9 {
10 this.GridView1.Rows[i].Visible = false; //如果该行未被选中,屏蔽!
11 }
12 }
13
14 this.GridView1.BottomPagerRow.Visible = false; //把页数,也屏蔽掉 就是 1 2 3 4页
15
16
17 Response.Buffer = true;
18 Response.Charset = "GB2312";
19 Response.AppendHeader("Content-Disposition", "attachment;filename=Exclefile.xls");
20 // 如果设置为 GetEncoding("GB2312");导出的文件将会出现乱码!!!
21 Response.ContentEncoding = System.Text.Encoding.UTF7;
22 Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。
23 System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
24 System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
25 this.GridView1.RenderControl(oHtmlTextWriter);
26 Response.Output.Write(oStringWriter.ToString());
27 Response.Flush();
28 Response.End();
29 }
30//下面这个函数一定要有的,否则会报错.
31 public override void VerifyRenderingInServerForm(Control control)
32 { }
前台页面:
Code
1//全选按钮代码
2 protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
3 {
4 if (((CheckBox)sender).Checked)
5 {
6 for (int i = 0; i < GridView1.Rows.Count; i++)
7 {
8 ((CheckBox)GridView1.Rows[i].FindControl("CheckBox2")).Checked = true;
9 }
10 }
11 else
12 {
13 for (int i = 0; i < GridView1.Rows.Count; i++)
14 {
15 ((CheckBox)GridView1.Rows[i].FindControl("CheckBox2")).Checked = false;
16 }
17 }
18 }
1//全选按钮代码
2 protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
3 {
4 if (((CheckBox)sender).Checked)
5 {
6 for (int i = 0; i < GridView1.Rows.Count; i++)
7 {
8 ((CheckBox)GridView1.Rows[i].FindControl("CheckBox2")).Checked = true;
9 }
10 }
11 else
12 {
13 for (int i = 0; i < GridView1.Rows.Count; i++)
14 {
15 ((CheckBox)GridView1.Rows[i].FindControl("CheckBox2")).Checked = false;
16 }
17 }
18 }