我的程序有问题。当我这样做时:
GridView gvw = this.ProduttoriList1.FindControl("GridViewList") as GridView;
SqlDataSource dataSource = this.ProduttoriList1.FindControl(gvw.DataSourceID) as SqlDataSource;
FileInfo tempXlsFile = new FileInfo(HttpRuntime.CodegenDir + "\\" + Guid.NewGuid() + ".xlsx");
string filename = string.Format("Produttori_{0}.xlsx", Guid.NewGuid().ToString());
try
{
gvw.AllowPaging = false;
gvw.DataSourceID = string.Empty;
gvw.DataSource = dataSource;
gvw.DataBind();
//...some export commands with EPPlus...
}
catch (Exception exception)
{
throw exception;
}
finally
{
System.IO.File.Delete(tempXlsFile.ToString());
}
我要读取 HeaderRow,我无法读取具有 SortExpression 的列(返回“”值)。
<asp:Panel ID="Panel2" runat="server" Style="padding-top: 10px">
<asp:GridView ID="GridViewList" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSourceList"
Width="100%" AllowPaging="True" AllowSorting="True" SkinID="GridViewDefault"
DataKeyNames="id">
<Columns>
<asp:TemplateField HeaderStyle-Width="30px" HeaderText="N°">
<ItemTemplate>
<%# Container.DataItemIndex + 1 %>.
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="DescrLongITA" HeaderText="Produttore" SortExpression="DescrLongITA" />
<asp:TemplateField HeaderText="Modifica">
<ItemTemplate>
<asp:ImageButton ID="ImageButtonEdit" runat="server" ImageUrl="~/Images/Icons/modifica.gif"
CommandArgument='<%# Eval("ID") %>' OnClick="ImageButtonEdit_Click" />
</ItemTemplate>
<HeaderStyle Width="60px" />
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Elimina">
<ItemTemplate>
<asp:ImageButton ID="ImageButtonDelete" runat="server" CommandName="Delete" ImageUrl="~/Images/Icons/elimina.gif"
OnClientClick="return confirm("Continuare la cancellazione?")" CommandArgument='<%# Eval("ID") %>'
OnClick="ImageButtonDelete_Click" />
</ItemTemplate>
<HeaderStyle Width="60px" />
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
<div style="color: #FF0000; padding: 30px">
<asp:Label ID="LabelEmpty1" runat="server" Text="Nessun dato trovato"></asp:Label>
</div>
</EmptyDataTemplate>
</asp:GridView>
</asp:Panel>
在这种情况下,我无法读取 HeaderText = "Produttore" 的 BoundField。
我能怎么做?