Solved

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

Posted on 2014-09-05
4
1,002 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP.NET Calendar Control 5 54
aspx ascx, c# 7 45
Disable the weekends on datepicker control 6 52
UWP: Create an Image/Bitmap, Draw another image on it an save. 1 47
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

752 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