FineUI 官方论坛
标题:
导出数据错误,请帮忙看下,谢谢
[打印本页]
作者:
yfen
时间:
2013-8-21 17:02
标题:
导出数据错误,请帮忙看下,谢谢
gridClientID “gridClientID”未定义 Error
代码如下:
<x
ageManager ID="
ageManager1" AutoSizePanelID="
anel1" runat="server"></x
ageManager>
<x
anel ID="
anel1" runat ="server" BodyPadding="5px" EnableBackgroundColor="true" ShowBorder="true" ShowHeader ="false" Title="aaa" Layout="Fit" EnableAjax="true" >
<Items>
<x:Grid ID="Grid1" runat="server" EnableCheckBoxSelect="true" EnableRowNumber="true" AllowPaging="true" PageSize ="15" ShowHeader="false" DataKeyNames="sfzh" ForceFitAllTime="true" AllowCellEditing="true" AllowSorting="true" SortColumnIndex="2" SortDirection="ASC" EnableHeaderMenu="true" EnableColumnLines="true">
<Toolbars>
<x:Toolbar ID="Toolbar1" runat="server">
<Items>
<x:Button ID="btnExcle" Text="将Grid导出为Excel文件" Icon="Delete" runat="server" />
</Items>
</x:Toolbar>
</Toolbars>
<Columns>
<x:BoundField TextAlign="Center" DataField ="bm" SortField="bm" HeaderText="部门" DataFormatString = "{0}" Width="60px" />
<x:BoundField TextAlign="Center" DataField="xm" HeaderText="姓名" ColumnID="xm"/>
<x:BoundField TextAlign="Center" DataField="sfzh" HeaderText="身份证" ColumnID="sfzh" SortField="sfzh" />
<x:BoundField TextAlign="Center" DataField="ygz" HeaderText="原工资" ColumnID="ygz" />
<x:BoundField TextAlign="Center" DataField="xb" HeaderText="性别" ColumnID="xb" SortField="xb"/>
<x:BoundField TextAlign="Center" DataField="gh" HeaderText="工号" ColumnID="gh" SortField="gh" />
<x:BoundField TextAlign="Center" DataField="djrq" HeaderText="登记日期" ColumnID="djrq" />
</Columns>
<
ageItems>
<x:ToolbarSeparator ID="ToolbarSeparator1" runat="server">
</x:ToolbarSeparator>
<x:ToolbarText ID="ToolbarText1" runat="server" Text="每页记录数:">
</x:ToolbarText>
<x
ropDownList runat="server" ID="ddlPageSize" Width="80px" AutoPostBack="true" OnSelectedIndexChanged="ddlPageSize_SelectedIndexChanged">
<x
istItem Text="5" Value="5" />
<x
istItem Text="10" Value="10" />
<x
istItem Text="15" Value="15" />
<x
istItem Text="20" Value="20" />
<x
istItem Text="30" Value="30" />
<x
istItem Text="40" Value="40" />
<x
istItem Text="50" Value="50" />
</x
ropDownList>
</PageItems>
</x:Grid>
</Items>
</x
anel>
后台代码:
//导出到Excles按钮
protected void btnExcle_Click(object sender, EventArgs e)
{
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment; filename=MyExcelFile.xls");
Response.ContentType = "application/excel";
Response.Charset = "GB2312";
Response.Write(GetGridTableHtml(Grid1));
Response.End();
}
private string GetGridTableHtml(Grid grid)
{
StringBuilder sb = new StringBuilder();
sb.Append("<table cellspacing=\"0\" rules=\"all\" border=\"1\" style=\"border-collapse:collapse;\">");
sb.Append("<tr>");
foreach (GridColumn column in grid.Columns)
{
sb.AppendFormat("<td>{0}</td>", column.HeaderText);
}
sb.Append("</tr>");
foreach (GridRow row in grid.Rows)
{
sb.Append("<tr>");
foreach (object value in row.Values)
{
string html = value.ToString();
sb.AppendFormat("<td style='vnd.ms-excel.numberformat
'>{0}</td>", html);
}
sb.Append("</tr>");
}
sb.Append("</table>");
return sb.ToString();
}
以前的项目导出数据正确,升级3.31后错误,不知为何?
作者:
yfen
时间:
2013-8-21 17:20
已解决在按钮中少了个属性EnableAjax="false",加上即可
作者:
sanshi
时间:
2013-8-21 18:22
yfen 发表于 2013-8-21 17:20
已解决在按钮中少了个属性EnableAjax="false",加上即可
看下这篇文章:
http://www.cnblogs.com/sanshi/archive/2012/11/20/2778332.html
欢迎光临 FineUI 官方论坛 (https://fineui.com/BBS/)
Powered by Discuz! X3.4