office

位置:IT落伍者 >> office >> 浏览文章

ListView中的内容以Excel导出


发布日期:2024年07月02日
 
ListView中的内容以Excel导出

<div>

<asp:ListView ID=ListView runat=server>

<ItemTemplate>

<tr>

<td id=Td runat=server >

<asp:Label ID=idLabel runat=server Text=<%# Eval(name) %> />

<br />

</td>

<td>

<asp:Label ID=xLabel runat=server Text=<%# Eval(Age) %> />

<br />

</td>

</tr>

</ItemTemplate>

<LayoutTemplate>

<table id=Table runat=server border= >

<tr runat=server id=itemPlaceholder />

</table>

</LayoutTemplate>

</asp:ListView>

</div><asp:Button ID=Button runat=server Text=Button

onclick=Button_Click />

后台代码

public partial class ListView_Code : SystemWebUIPage

{

DataAccess da;

protected void Page_Load(object sender EventArgs e)

{

if (Session[da] == null)

{

da = new DataAccess();

Session[da] = da;

}

else

{

da = Session[da] as DataAccess;

}

if (!IsPostBack)

{

Bind();

}

}

private void Bind()

{

ListViewDataSource = daList;

ListViewDataBind();

}

private void Export(string FileType string FileName)

{

ResponseCharset = GB;

ResponseContentEncoding = SystemTextEncodingUTF;

ResponseAppendHeader(ContentDisposition attachment;filename= + HttpUtilityUrlEncode(FileName EncodingUTF)ToString());

ResponseContentType = FileType;

thisEnableViewState = false;

StringWriter tw = new StringWriter();

HtmlTextWriter hw = new HtmlTextWriter(tw);

ListViewRenderControl(hw);

ResponseWrite(twToString());

ResponseEnd();

}

protected void Button_Click(object sender EventArgs e)

{

Export(application/msexcel employeexls);

}

}

               

上一篇:Sandcastle同NDoc的比较

下一篇:VB连接Excel文件