Does anyone have an example of GridView (Web aspx) without using the database?
I'm using Cobol native files, is to populate a GridView that way?

Thank you

Alguém tem um exemplo de GridView (Web aspx) sem usar banco de dados ?
Só estou utilizando arquivos nativos Cobol, tem como popular um GridView dessa forma?


  • Verified Answer

    I would recommend that you use the same method to populate the grid with records from a COBOL data file that you would when you get the data from a database, create a List or Collection object containing the data and bind this to the grid.

    The example code below shows you one way that you can do this by calling a COBOL program that reads the file and places each record into a CustData object which is then added to a List. The List is then returned to the main form and it is bound to the gridview control.

      method-id Button1_Click protected.
           01 mylist list[type CustData].
           procedure division using by value sender as object e as type System.EventArgs.
               declare myrununit as type RunUnit = new RunUnit
                  set mylist to myrununit::CallObject("getrecords") as List[type CustData]
                  set errormsg::Text to exception-object::Message
                  invoke myrununit::StopRun
               set GridView1::DataSource to mylist  
               invoke GridView1::DataBind 
           end method.

    called program:

           program-id. getrecords as "WebGridview.getrecords".
               select cust-file assign to "C:\WebGridview\WebGridview\WebGridview\App_Data\custfile.txt"
                                organization is line sequential
                                file status is file-status.
           data division.
           fd cust-file.
           01 cust-record.
              05 cust-name   pic x(20).
              05 cust-company pic x(20).
              05 cust-phone  pic x(15).
           working-storage section.
           01 file-status    pic x(2) value spaces.
           01 mydata type CustData.
           01 mylist list[type CustData] value new List[type CustData].
           procedure division returning mylist.
               open input cust-file
               if file-status = "00"
                  perform until exit
                     read cust-file
                        at end
                           exit perform
                        not at end
                           set mydata to new CustData
                           set mydata::CustName to cust-name
                           set mydata::Company to cust-company
                           set mydata::Phone to cust-phone
                           invoke mylist::Add(mydata)
               close cust-file
           end program getrecords.


    class-id WebGridview.CustData public.
           working-storage section.
           01 CustName  string property.
           01 Company   string property.
           01 Phone     string property.
           end class.
  • Chris, thanks for the help but I could not understand where to put it in my project. Confused

  • If you tell me how your project is currently organized perhaps I can make some suggestions. You can update the individual columns of the gridview itself with data but binding to a collection object is really a better way to accomplish this,

    Is there a specific question that I can help you with regarding this example?

  • Thank you Chris, see this example I did, but there's something wrong do not understand RunUnit

    Obrigado Chris, veja este exemplo que fiz, mas tem alguma coisa errada não entendo o RunUnit.

  • Verified Answer

    Right-click on the Project References folder and select Add Reference and then select the assembly MicroFocus Runtime (Interop RuntimeServices) 4.0 which is listed under the Extensions section.

    This will add MicroFocus.COBOL.RuntimeServices.dll to your project. This contains the RunUnit class.

    Then add the following directive to the top of Default.aspx.cbl

    $set ilusing"MicroFocus.COBOL.RuntimeServices"

    Your project will then compile successfully.

    In a multi-threaded environment like ASP.NET where each user request is handled by a separate thread, you must protect the resources that the COBOL programs use to make them thread safe. This is what the RunUnit class does. By creating an instance of the RunUnit class for each user request and then adding your top level COBOL program to the RunUnit and calling it, you will be protecting all resources of that program and any other program that it may call. This includes resources source as open files, database connections and working-storage data. If you did not use a RunUnit and just executed a CALL statement directly from your .aspx program then only one instance of the program would be created and shared by all threads. These threads would quickly be stomping all over each other.

    Documentation for RunUnits and multiuser programming can be found in the docs here:

    The actual documentation for the RunUnit class is in a separate help file which is documented here:

  • Chris, thank you!

    I will read this documentation, it worked!