Click here to Skip to main content
16,004,806 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
my code is
C#
public static string DGVtoString(DataGridView dgv)
       {
           string tab = "\t";
           StringBuilder sb = new StringBuilder();
        sb.AppendFormat("<html>");
            sb.AppendFormat("<body>");
            sb.Append("<table>");
           foreach (DataGridViewRow row in dgv.Rows)
           {
              sb.AppendFormat(tab + tab + tab + "<tr>");
               foreach (DataGridViewCell cell in row.Cells)
               {
                   sb.AppendFormat(tab + tab + tab + "<td>");
                        sb.Append(cell.Value);
                   sb.AppendFormat(tab + tab + tab + "<td>");

               }
               sb.AppendFormat("</tr>");

           }

           sb.Append(tab + tab + "</table>");
           sb.AppendFormat(tab + "</body>");
           sb.AppendFormat("</html>");
           return sb.ToString();
       }


What I have tried:

i got output with html tags insted of fix format.
Posted
Updated 15-Jun-16 17:58pm

1 solution

Hello Kumbhani, it's better to use RDLC report for showing your data tabular format on report.
Here is a reference,"How to create RDLC report".

Click Here

Note:- RDLC report provide some default export feature and you can easily show your data in PDF,Doc,Excel and others.

:)
 
Share this answer
 
Comments
Kumbhani Bhavesh 16-Jun-16 0:37am    
i got data in pdf but i can not get with format.
Shambhoo kumar 16-Jun-16 1:03am    
yes i was also faced same problem, there are some margin issue in your code. But if you use RDLC you easily fix these kind of issue. Better to use RDLC.
Kumbhani Bhavesh 17-Jun-16 1:38am    
do you have any other solution?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900