Tag: gridview

格式化GridView的BoundField,Excel不会将文本转换为date

我正在使用C#以编程方式使用GridView和BoundFields生成一个Excel文件。 现在它不断将某些值转换为date,而不是将它们保持为纯文本。 我希望他们留在从数据库返回,没有从Excel转换。 我已经探索了几个选项,但我似乎无法绕过这个转换。 这是直接到一个文件。 问题的BoundField是“ReportNumber”。 感谢您提供任何帮助。 代码片段: [HttpGet] public ActionResult AFDOJClosed2Excel(byte[] Data, string Reporting_Year) { try { DataTable dt = GetAFDOJClosed(Reporting_Year);//your datatable DataView dv = dt.DefaultView; dv.Sort = "Case_Number ASC"; DataTable sortedDT = dv.ToTable(); dt = sortedDT; GridView excel = new GridView(); excel.DataSource = dt; excel.AutoGenerateColumns = false; //Explicitly Create bound fields BoundField CaseNumber […]

如何从gridview值显示图表和graphics

我想再次寻求帮助:)有没有一种方法来显示图表值和graphicsgridview值? 什么即时尝试这样做是上传一个Excel文件,然后显示在GridView上。 (我能够做到这一点,我编码它与C#),但是我希望显示的图表值和graphics取自gridview的值。 即时通讯使用微软图表工具。 这可能吗? 谢谢,Nhoyti

如何在同一个excel文件中的不同工作表中导出两个gridviews?

我目前在我的页面上有两个GridView。 我能够导出一个gridview到excel文件。 但是对于第二个gridview,我希望它在同一个文件的另一个工作表中打开。 任何人都可以帮助我开始,并告诉我如何去做? 这是我的代码看起来像: protected void btnExport_Click(object sender, EventArgs e) { GridView gridView = null; System.IO.StringWriter stringWrite = null; System.Web.UI.HtmlTextWriter htmlWrite = null; try { gridView = new GridView(); List<string> columns = new List<string>(); columns.Add("CREATE_AR_YN"); columns.Add("GL_DEBIT_ACCT"); columns.Add("ALLOC_METHOD"); columns.Add("CUST_NAME"); columns.Add("DEFAULT_PYMT_TERMS"); columns.Add("AR_BILL_GROUP"); BoundField bf = null; for (int i = 0; i < columns.Count; i++) { […]

在asp.net中将从excel文件input的时间转换为gridview

我有一个excel文件,我在格式 – “10:14:16”添加时间,并添加代码 dt = ExcelLibrary.DataSetHelper.CreateDataTable(FilePath, "abc"); 在asp.net中的gridview中转换和显示这个excel文件。 它显示的值为“0.426574074074074” 。 我无法将此数据保存在SQL Server数据库中,因为我需要的格式与在Excel文件中提到的相同。 请帮帮我。

将GridView中不可见的列导出到Excel

我有一个ASP.Net网页(。NET 4.0,C#)有一些不可见的列的GridView 。 但是,用户希望这些列显示在Excel导出中。 我很难理解如何做到这一点。 我试着做一个BoundField和一个带有标签的TemplateField : <asp:TemplateField HeaderText="Device Comments" SortExpression="DeviceComments" Visible="false"> <ItemTemplate> <asp:Label runat="server" Text='<%# Eval("DeviceComments") %>' ID="lbDeviceComments" /> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="DeviceComments" HeaderText="Device Comments" SortExpression="DeviceComments" Visible="false" /> 按预期,这些列不会显示在网页上。 但是,当我尝试在导出到Excel的方法中使列可见时,它们保持不可见状态。 我试过了: protected void Export2Excel(object sender, EventArgs e) { Response.ClearContent(); Response.AppendHeader("content-disposition", "attachment; filename=Mobile.xls"); Response.ContentType = "application/excel"; StringWriter stringWriter = new StringWriter(); HtmlTextWriter htmlTextWriter = new […]

像在ASP.NET应用程序中筛选Excel

我有一个已经运行的asp.net(非MVC)Web窗体应用程序。 它有一个gridview。 <asp:GridView ID="gvPendingInvoices" runat="server" AutoGenerateColumns="false" Width="60%" AllowPaging="true" AllowSorting="true" CellPadding="4" OnPageIndexChanging="gvPendingInvoices_PageIndexChanging" OnRowDataBound="gvPendingInvoices_RowDataBound"> <PagerStyle CssClass="gridView_PaggerStyle" HorizontalAlign="Left" /> <HeaderStyle CssClass="gridView_HeaderStyle" HorizontalAlign="Left" /> <SelectedRowStyle CssClass="gridView_SelectedRowStyle" /> <FooterStyle CssClass="gridView_FooterStyle" /> <PagerStyle HorizontalAlign="Left" /> <AlternatingRowStyle CssClass="gridView_AlternatingRowStyle" /> <PagerSettings PageButtonCount="10" Position="TopAndBottom" /> <RowStyle BorderStyle="None" CssClass="gridView_RowStyle" /> <Columns> <asp:TemplateField HeaderText="ProjectId" Visible="false"> <ItemTemplate> <asp:Label runat="server" ID="lblProjectId" Text='<%# Bind("ProjectId") %>' /> </ItemTemplate> </asp:TemplateField> <asp:TemplateField […]

Asp.Net导入Excel不能在Web服务器上运行

我需要将我的Excel文件导入到网页上的gridview。 我使用这种连接方法; Dim connectionString As String If (Path.GetExtension(fullFileName).Equals(".xls")) Then connectionString = String.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=""Excel 8.0;HDR=YES;IMEX=2""", fullFileName) ElseIf (Path.GetExtension(fullFileName).Equals(".xlsx")) Then connectionString = String.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=""Excel 12.0 Xml;HDR=YES;IMEX=2""", fullFileName) End If Dim connExcel As OleDbConnection connExcel = New OleDbConnection(connectionString) connExcel.Open() 当我在本地主机上运行它工作正常。 但是,我通过FTP传输项目到服务器后,它不会带来相同的结果。 换句话说,连接失败。 编辑:我拿这个错误; “Microsoft.ACE.OLEDB.12.0”提供程序未在本地计算机上注册

以一般格式将GridView导出到Excel

我正试图将我的GridView导出到Excel 。 问题是当我导出默认格式我设置为Text但我希望它在General 。 以下是我如何导出Excel: Response.Clear() Response.Charset = "" Response.AddHeader("content-disposition", "attachment;filename=RawTransactionReport.xls") 'set the response mime type for excel Response.ContentType = "application/vnd.ms-excel" 'create a string writer Dim stringWrite As New System.IO.StringWriter 'create an htmltextwriter which uses the stringwriter Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite) 'tell the datagrid to render itself to our htmltextwriter grdTransactions.RenderControl(htmlWrite) 'shows number in […]

导出嵌套的Gridview到Excel错误

我需要使用以下代码将嵌套的Gridview导出到Excel中,但是当我单击“导出”button时,它引发了一个错误: mscorlib.dll中发生types“System.ArgumentOutOfRangeException”的exception,但未在用户代码中处理 这是代码: protected void ExportExcel(object sender, EventArgs e) { DataTable dt = new DataTable("GridView_Data"); GridView grvPayrollDetails = (GridView)grvPayroll.Rows[1].FindControl("grvPayrollDetails"); foreach (TableCell cell in grvPayroll.HeaderRow.Cells) { dt.Columns.Add(cell.Text); } foreach (TableCell cell in grvPayrollDetails.HeaderRow.Cells) { dt.Columns.Add(cell.Text); } dt.Columns.RemoveAt(0); foreach (GridViewRow row in grvPayroll.Rows) { GridView grvPayrollDetailscell = (row.FindControl("grvPayrollDetails") as GridView); for (int j = 0; j < […]

如何保存自动生成gridview列的Excel中的数据?

我知道这可能是一个重复的问题,但我无法find任何地方。 我从excel导入数据到gridview,但如何将gridview数据保存到数据库中,并从gridview列自动生成。 数据已经反映在gridview中,我如何将它保存在数据库中? 如果有人能教我如何直接从excel插入到数据库而不使用gridview作为媒介,会更好(尝试使用这种方式,但一直告诉我excel表单不存在)。 绑定网格视图的代码: string conStr = ""; switch (Extension) { case ".xls": //Excel 97-03 conStr = ConfigurationManager.ConnectionStrings["Excel03ConString"] .ConnectionString; break; case ".xlsx": //Excel 07 conStr = ConfigurationManager.ConnectionStrings["Excel07ConString"] .ConnectionString; break; } conStr = String.Format(conStr, FilePath, isHDR); OleDbConnection connExcel = new OleDbConnection(conStr); OleDbCommand cmdExcel = new OleDbCommand(); OleDbDataAdapter oda = new OleDbDataAdapter(); DataTable dt = new […]