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 try set mylist to myrununit::CallObject("getrecords") as List[type CustData] catch set errormsg::Text to exception-object::Message finally invoke myrununit::StopRun end-try set GridView1::DataSource to mylist invoke GridView1::DataBind goback. 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) end-read end-perform end-if close cust-file goback. end program getrecords.
Class:
class-id WebGridview.CustData public. working-storage section. 01 CustName string property. 01 Company string property. 01 Phone string property. end class.