Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

896 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

16 Experts available now in Live!

Get 1:1 Help Now