asp.net GridviewÖеÄÄÚÈݵ¼³öµ½Excel
1£ºGridviewÖеÄÄÚÈݵ¼³öµ½Excel¡¡
¡¡Asp.net 2.0ÖÐÐÂÔöµÄgridview¿Ø¼þ£¬ÊÇÊ®·ÖÇ¿´óµÄÊý¾Ýչʾ¿Ø¼þ£¬ÔÚÇ°ÃæµÄϵÁÐÎÄÕÂÀ·Ö±ðչʾÁËÆäÖкܶàµÄ»ù±¾Ó÷¨ºÍ¼¼ÇÉ¡£ÔÚ±¾ÎÄÖУ¬½«¼ÌÐøÌ½ÌÖÓйصļ¼ÇÉ¡£
¡¡¡¡Ò»¡¢GridviewÖеÄÄÚÈݵ¼³öµ½Excel
¡¡¡¡ÔÚÈÕ³£¹¤×÷ÖУ¬¾³£Òª½«gridviewÖеÄÄÚÈݵ¼³öµ½excel±¨±íÖÐÈ¥£¬ÔÚasp.net 2.0ÖУ¬Í¬Ñù¿ÉÒԺܷ½±ãµØÊµÏÖ½«Õû¸ögridviewÖеÄÄÚÈݵ¼³öµ½excel±¨±íÖÐÈ¥£¬ÏÂÃæ½éÉÜÆä¾ßÌå×ö·¨£º
¡¡¡¡Ê×ÏÈ£¬½¨Á¢»ù±¾µÄÒ³Ãædefault.aspx
£¼form id="form1" runat="server"£¾
£¼div£¾
£¼asp:GridView ID="GridView1" runat="server"£¾
£¼/asp:GridView£¾
£¼/div£¾
£¼br/£¾
£¼asp:Button ID="BtnExport" runat="server" OnClick="BtnExport_Click"
Text="Export to Excel" /£¾
£¼/form£¾
¡¡¡¡ÔÚdefault.aspx.csÖУ¬Ð´ÈëÈçÏ´úÂ룺
protected void Page_Load(object sender, EventArgs e)
{
¡¡if (!Page.IsPostBack)
¡¡{
¡¡¡¡BindData();
¡¡}
}
private void BindData()
{
¡¡string query = "SELECT * from customers";
¡¡SqlConnection myConnection = new SqlConnection(ConnectionString);
¡¡SqlDataAdapter ad = new SqlDataAdapter(query, myConnection);
¡¡DataSet ds = new DataSet();
¡¡ad.Fill(ds, "customers");
¡¡GridView1.DataSource = ds;
¡¡GridView1.DataBind();
}
public override void VerifyRenderingInServerForm(Control control)
{
¡¡// Confirms that an HtmlForm control is rendered for
}
protected void Button1_Click(object sender, EventArgs e)
{
¡¡Response.Clear();
¡¡Response.AddHeader("content-disposition","attachment;filename=FileName.xls");
¡¡Response.Charset = "gb2312";
¡¡Response.ContentType = "application/vnd.xls";
¡¡System.IO.StringWriter stringWrite = new System.IO.StringWriter();
¡¡System.Web.UI.HtmlTextWriter htmlWrite =new HtmlTextWriter(stringWrite);
¡¡GridView1.AllowPaging = false;
¡¡BindData();
¡¡GridView1.RenderControl(htmlWrite);
¡¡Response.Write(stringWrite.ToString());
¡¡Response.End();
¡¡GridView1.AllowPaging = true;
¡¡BindData();
}
protected void paging(object sender,GridViewPageEventArgs e)
{
¡¡GridView1.PageIndex = e.NewPageIndex;
¡¡BindData();
}
¡¡¡¡ÔÚÉÏÃæ
Ïà¹ØÎĵµ£º
BehaviorEditorPart Web ·þÎñÆ÷¿Ø¼þÊÇÒ»¸ö±à¼Æ÷²¿¼þ¿Ø¼þ£¬×îÖÕÓû§¿ÉÒÔʹÓøÿؼþÔÚÔËÐÐʱ¸ü¸Ä¹ØÁªµÄ WebPart ¿Ø¼þÉϵĶà¸öÓû§½çÃæ (UI) ÊôÐÔ¡£Ï±íÁгöÁËÓû§¿É×Ô¶¨ÒåµÄ¹¦ÄÜ£¬ÒÔ¼°Óû§¿ÉʹÓà BehaviorEditorPart ¿Ø¼þ±à¼µÄ¶ÔÓ¦µÄ WebPart ¿Ø¼þÊôÐÔÖµ¡£
Óû§¿É×Ô¶¨ÒåµÄ¹¦ÄÜ
WebPart ......
¾Å¡¢ASP.NETÖÐGDI+
protected void Page_Load(object sender, EventArgs e)
{
string Filename;
System.Drawing.Image g;
&nbs ......
string filepath = FileUpload1.FileName; &nb ......
ÓÐʱºòÐèÒª¶¯Ì¬µÄÉèÖà WebService µÄÖ·£¬ÕâÑù·¢²¼µ½²»Í¬µÄ·þÎñÆ÷ʱ¾ÍÒªÖØÐÂÉú³É£¬Îª´ËÎÒÃÇÐèÒªÔÚweb.configÖж¯Ì¬ÅäÖÃWebServiceµÄµØÖ·£¬ÔÚÍøÉϲéÁ˺ܶà×ÊÁÏ£¬ÆäÖÐÕâÖÖ·½·¨¸Ð¾õºÜºÃÓÃÒ²ºÜºÃʵÏÖ£¬ÔÎÄVB.NETʵÏÖ¡£±¾ÈËÒѸÄΪC#°æ
¡¡¡¡Ê×ÏÈÊÖ¶¯µÄÌí¼ÓÒ»¸öWebÒýÓã¨Õâ¸ö¾Í²»ÓÃ˵Á˰ɣ©
¡¡¡¡È»ºóÐ޸ı¾µØµÄ´úÀíÀࣨÌí¼ÓÒ»¸öÐ ......