Link to home
Start Free TrialLog in
Avatar of R8VI
R8VI

asked on

Create table dynamically and isnert data c#, asp.net

Hi,

I have the code below.

What I want to do is create the rows and cells and insert the data dynamically, but this seems like a loop that does not end please helps

dgFindClient.Rows.Count is set to 2

  //// Create a new table
            DocumentFormat.OpenXml.Wordprocessing.Table tbl = new DocumentFormat.OpenXml.Wordprocessing.Table();

            int icountRowsinService = dgFindClient.Rows.Count; 
            int icounterfortableservice;
            for (icounterfortableservice = 0; icounterfortableservice < icountRowsinService; icountRowsinService++)
            {    

                //// Create a new row
                DocumentFormat.OpenXml.Wordprocessing.TableRow tr = new DocumentFormat.OpenXml.Wordprocessing.TableRow();

                //// Add a cell to each column in the row
                DocumentFormat.OpenXml.Wordprocessing.TableCell tablecellService = new DocumentFormat.OpenXml.Wordprocessing.TableCell(new Paragraph(new Run(new Text("Vijai"))));
                DocumentFormat.OpenXml.Wordprocessing.TableCell tablecellServicePrice = new DocumentFormat.OpenXml.Wordprocessing.TableCell(new Paragraph(new Run(new Text("1"))));

                //// Add the cells to the row
                tr.Append(tablecellService, tablecellServicePrice);

               
                //// Add the rows to the table
                tbl.AppendChild(tr);
           
            }
           
     

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ramkisan Jagtap
Ramkisan Jagtap
Flag of Finland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of R8VI
R8VI

ASKER

Hi thanks for this but can you point out where the problem was in the loop please
Old loop statement:   for (icounterfortableservice = 0; icounterfortableservice < icountRowsinService; icountRowsinService++)
           
New loop statement: for (icounterfortableservice = 0; icounterfortableservice < icountRowsinService; icounterfortableservice++)

Check the variable used in ++
If you keep increasing icountRowsinService loop will never end.