Solved

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

Posted on 2014-09-05
4
920 Views
Last Modified: 2014-09-08
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

0
Comment
Question by:R8VI
  • 3
4 Comments
 
LVL 12

Accepted Solution

by:
Ramkisan Jagtap earned 500 total points
ID: 40306910
There is problrm in you loop. Check the corrected code
//// 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; icounterfortableservice++)
            {    

                //// 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);
           
            }
0
 

Author Comment

by:R8VI
ID: 40306989
Hi thanks for this but can you point out where the problem was in the loop please
0
 
LVL 12

Expert Comment

by:Ramkisan Jagtap
ID: 40307047
Old loop statement:   for (icounterfortableservice = 0; icounterfortableservice < icountRowsinService; icountRowsinService++)
           
New loop statement: for (icounterfortableservice = 0; icounterfortableservice < icountRowsinService; icounterfortableservice++)

Check the variable used in ++
0
 
LVL 12

Expert Comment

by:Ramkisan Jagtap
ID: 40307048
If you keep increasing icountRowsinService loop will never end.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Initial get page response times and IIS8 15 51
SqlDataBase 7 48
C# Desktop Application 3 36
How to design the database - Asp.net mvc code first entity framework 1 40
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question