如何在启用分页时显示网格视图中的完整数据?

时间:2010-03-31 05:37:36

标签: asp.net

我在将数据从网格显示到excel时出现问题。我已经实现了分页,问题是显示的页面只导出到excel而不是所有页面。

3 个答案:

答案 0 :(得分:0)

您可以考虑创建第二个页面,该页面显示网格中的数据但关闭了分页。这样,所有数据都将导出到Excel

答案 1 :(得分:0)

如果您从数据库中获取所有记录并将其存储在本地,那么您可能会考虑从该源导出数据。不是来自数据网格,因为它实现了Paging,它包含在页面大小的记录上。

答案 2 :(得分:0)

//导出实际数据集

            if (rds != null && rds.Tables.Count != 0)
            {

                #region WriteToTheStringBuilder
                DataTable dt = rds.Tables[0];
                StringBuilder str = new StringBuilder ();
                //first add the column names 
                for (int j = 0; j <= dt.Columns.Count - 1; j++)
                {
                    //comm -- remove only one tab if exists from each cell
                    str.Append ( dt.Columns[j].ToString () + "\t" );
                }
                str.AppendLine();
                //comm -- than add by row the whole table

                for (int i = 0; i <= dt.Rows.Count - 1; i++)
                {
                    for (int j = 0; j <= dt.Columns.Count - 1; j++)
                    {
                        //comm -- remove only one tab if exists from each cell
                        str.Append ( Utils.Str.Str.FindAndReplace (
                                                                                        dt.Rows[i][j].ToString (), "(.*)(\t)(.*)", "$1$3" ) + "\t" );
                    }

                    str.AppendLine();
                }
                #endregion WriteToTheStringBuilder


                #region WriteToResponse
                //<source>http://geekswithblogs.net/brcraju/archive/2005/07/27/48372.aspx</source>
                HttpContext.Current.Response.Clear();
                HttpContext.Current.Response.ClearContent();
                HttpContext.Current.Response.ClearHeaders();
                HttpContext.Current.Response.Buffer = true;
                HttpContext.Current.Response.ContentType = "application/vnd." + fileExtension; 
                //HttpContext.Current.Response.Write(@"<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">");

                #region IftheExportingServerIsBehindFirewall
                bool flagUseDnsRemapping = false;
                flagUseDnsRemapping = Convert.ToBoolean(Convert.ToInt16(Resources.GV.UseSecureConnection));

                if (flagUseDnsRemapping == true)
                    HttpContext.Current.Response.AddHeader("Host", Resources.GV.ServerDNSName);

                #endregion IftheExportingServerIsBehindFirewall
                HttpContext.Current.Response.AddHeader("content-disposition",
                "attachment;filename=" + pageName + "." + fileExtension);
                HttpContext.Current.Response.Charset = " "; //utf will brake thinks ...
                HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("windows-1250"); //windows-1250
                //HttpContext.Current.Response.Cache.SetCacheability ( HttpCacheability.NoCache );

// System.IO.StringWriter stringWrite = new System.IO.StringWriter(); // System.Web.UI.HtmlTextWriter htmlWrite = // new HtmlTextWriter(stringWrite);                     HttpContext.Current.Response.Write(str.ToString());                     HttpContext.Current.Response.Flush();                     HttpContext.Current.Response.End();                     #endregion WriteToResponse

                userObj.Mc.Msg  = "Export to Excel performed successfully ";
                return true;
            } //eof if