Solved

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

Posted on 2014-09-05
4
859 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

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…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now