//后台页面
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
protected void Page_Load(object sender, EventArgs e)
{
if( !IsPostBack )
{
GRBind();
}
}
//导出表 到 Excel word
protected void Button_Click( object sender, CommandEventArgs e )
{
switch( e.CommandName )
{
case "save":
switch( DropDownList1.SelectedValue )
{
case "excel":
OutPut( "attachment;filename=out.xls", "application/ms-excel" );
break;
case "word":
OutPut( "attachment;filename=out.doc", "application/ms-word" );
break;
}
break;
case "open":
switch( DropDownList1.SelectedValue )
{
case "excel":
OutPut( "online;filename=out.xls", "application/ms-excel" );
break;
case "word":
OutPut( "online;filename=out.doc", "application/ms-word" );
break;
}
break;
}
}
private void OutPut( string fileType, string strType )
{
Response.Clear();
Response.Buffer = true;
Response.Charset = "GB2312";
Response.AppendHeader( "Content-Disposition", fileType );
Response.ContentType = strType;
this.EnableViewState = false;
System.IO.StringWriter swOut = new System.IO.StringWriter();
HtmlTextWriter hTw = new HtmlTextWriter( swOut );
GridView1.RenderControl( hTw );
Response.Write( swOut.ToString() );
Response.End();
}
public override void VerifyRenderingInServerForm( Control control )
{
}
protected void DisplayNews_PageIndexChanging( object sender, GridViewPageEventArgs e )
{
GridView1.PageIndex = e.NewPageIndex;
//GRBind( Session[ "username" ].ToString() );
}
//private void GRBind( string userName )
private void GRBind()
{
//DataSet ds = new DataSet();
//string strWhere = " Note.typeid = Type.typeid and Note.username = '" + userName + "' ";
//ds = bn.GetList( strWhere );
newsDao.newsDao nd=new newsDao.newsDao();
this.GridView1.DataSource = nd.get_news();
this.GridView1.DataBind();
}