How to export gridpanel from code behind ?

  1. #1

    How to export gridpanel from code behind ?

    If i have a gridpanel defined in the code behind the form how can i export it ? (getRowsValues) ? using direct methods ?
    The definition of the button :
    <DirectEvents>     
    <Click OnEvent="ExportEt" IsUpload="true" >  
    <ExtraParams> 
    <ext:Parameter Name="data" Value="?????????????????????????" Mode="Raw" Encode="true" />
    <ext:Parameter Name="format" Value="csv" Mode="Value" /> 
    </ExtraParams>                                            
    </Click>                                        
    </DirectEvents>
    the definition of the gridpanel
     Protected Function grid_export() As GridPanel
            Dim zzz As New GridPanel
            Dim yyy As New Store
            yyy.Data = querydbdata(Session("stoc_select").ToString)
            zzz.Add(yyy)
            Return zzz
        End Function
    Thank you
  2. #2
  3. #3
    Quote Originally Posted by RCN View Post
    Thank you for the quick reply. I saw those examples but couldn't figure how to adapt them to my situation.
    1st example shows the propery with a hidden field wich get the calues from the gridpanel defined in the aspx form , and on the second one is the store submit event wich is used , again, from the aspx page definition.
    I need the submit event from the code behind.
    Image an empty aspx page with one button that on the code behind defines a gridpanel, a store, populate the store (already done) and after that submit the store value (here i didn't understood how to do it)....
  4. #4
    1 - View
    <!DOCTYPE html>
    <html>
    <head id="Head1" runat="server">
        <title>Index</title>
        <script type="text/javascript">
            var exportExcel = function () {
                Ext.net.DirectMethod.request({
                    url: "/Example/ExportExcel",
                    cleanRequest: true,
                    isUpload: true
                });
            }
        </script>
    </head>
    <body>
        <ext:ResourceManager ID="ResourceManager1" runat="server" />
        <ext:Button ID="Button1" Text="Export Excel" Icon="PageExcel" runat="server">
            <Listeners>
                <Click Handler="exportExcel();" />
            </Listeners>
        </ext:Button>
    </body>
    </html>
    2 - Controller
    public class ExampleController : System.Web.Mvc.Controller
    {
        public ActionResult Index()
        {
            return View();
        }
    
        public ActionResult ExportExcel()
        {
            List<Person> lst = new List<Person>();
    
            for (int index = 0; index < 10; index++)
            {
                lst.Add(new Person
                {
                    Name = "Name" + index,
                });
            }
    
            var xt = new System.Xml.Xsl.XslCompiledTransform();
            var submitData = new Ext.Net.SubmitHandler(JSON.Serialize(lst));
            System.Xml.XmlNode xml = submitData.Xml;
    
            var s = new StringBuilder();
            var settings = new System.Xml.XmlWriterSettings()
            {
                ConformanceLevel = System.Xml.ConformanceLevel.Auto
            };
    
            FileContentResult result = null;
            xt.Load(Server.MapPath("~/Resources/Excel.xsl"));
            System.Xml.XmlWriter writer = System.Xml.XmlWriter.Create(s, settings);
            xt.Transform(xml, writer);
            result = new FileContentResult(Encoding.UTF8.GetBytes(s.ToString()), "application/vnd.ms-excel");
            result.FileDownloadName = "Temp.xls";
    
            return result;
        }
    
        public StoreResult LoadFakeRecords()
        {
    
            List<Person> lst = new List<Person>();
    
            for (int index = 0; index < 10; index++)
            {
                lst.Add(new Person
                {
                    Name = "Name" + index
                });
            }
    
            return new StoreResult(lst, lst.Count());
        }
    }
    3 - Utility
    public class Person
    {
        public string Name { get; set; }
    }
  5. #5
    Thank you.
    Yes , it is something i need. The problem is i work in VB.NET and i get an error at this line
    Dim submitData = New Ext.Net.SubmitHandler(Json.Serialize(lst))
    it says : Overload resolution failed because no accessible 'Json' accepts this number of arguments.
    Can u reformulate the answer based on a store?
    instead of the list to use the store elements ?
  6. #6
    Please take a look on the following post:
    http://forums.ext.net/showthread.php...ll=1#post95551
  7. #7
    Quote Originally Posted by RCN View Post
    Please take a look on the following post:
    http://forums.ext.net/showthread.php...ll=1#post95551
    in that example i face again my problem : params: { data: App.GridPanel1.getRowsValues() }
    how do i change app.gridpanel1.getrowsvalues with my function that return a gridpanel ?
    i have
      Protected Function grid_export() As GridPanel
            Dim zzz As New GridPanel
            Dim yyy As New Store
            yyy.Data = querydbdata(Session("stoc_select").ToString)
            zzz.Add(yyy)
            Return zzz
        End Function
    if i just use app.grid_export.getRowsValues i get error.....
  8. #8

Similar Threads

  1. [CLOSED] How to Export SVG chart from code behind
    By feanor91 in forum 2.x Legacy Premium Help
    Replies: 4
    Last Post: Jun 27, 2013, 6:20 AM
  2. Replies: 1
    Last Post: Apr 19, 2010, 2:44 PM
  3. Export data from GridPanel to Pdf
    By marcmvc in forum 1.x Help
    Replies: 2
    Last Post: Oct 17, 2009, 3:42 AM
  4. [CLOSED] Export GridPanel and LoadMask
    By jchau in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Apr 14, 2009, 1:35 PM
  5. How to export GridPanel to the Excel?
    By jachnicky in forum 1.x Help
    Replies: 3
    Last Post: Dec 01, 2008, 4:57 PM

Posting Permissions