Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,

I'm just a starter in development. Actually, i'm developing an application for the productive hours. As everyone knows that, in a day we work on different projects. In that,i am trying to fetch the data between dates for some of the employees in excel sheet. Some basic details of the employee is getting repeated in each and every line. So i've written the code as

public string ConvertDataTableToHTMLTable()
        {
            StringBuilder sbuilder = new StringBuilder();
            
            sbuilder.Append("<html><title></title><head></head><body>");
            sbuilder.Append("");
            sbuilder.Append("<table border=1><tr>");

            for (int i = 0; i < dt.Columns.Count; i++)
            {
                sbuilder.Append("<td>" + dt.Columns[i].ColumnName + "</td>");
            }

            sbuilder.Append("</tr>");

            string strToken = string.Empty;
            string strDate = string.Empty;
            
            foreach (DataRow drRow in dt.Select(" ", "TokenNo asc"))
            {
                sbuilder.Append("<tr>");
                if (strToken != drRow["TokenNo"].ToString())
                {
                      strToken = drRow["TokenNo"].ToString();
                      strDate = drRow["Date"].ToString();
                        DataRow[] drRows = dt.Select("TokenNo='" + strToken + "'");
                        int len = drRows.Length;
                        DataRow[] drRows1 = dt.Select("Date='" + strDate + "'");
                        int len1 = drRows1.Length;
                        sbuilder.Append("<td rowspan='" + len + "'>");
                        sbuilder.Append(drRow["Name"].ToString() + "</td>");
                        sbuilder.Append("<td rowspan='" + len + "'>");
                        sbuilder.Append(drRow["TokenNo"].ToString() + "</td>");
                        sbuilder.Append("<td rowspan='" + len + "'>");
                        sbuilder.Append(drRow["TeamLeader"].ToString() + "</td>");
                        sbuilder.Append("<td rowspan='" + len + "'>");
                        sbuilder.Append(drRow["Date"].ToString() + "</td>");
                        sbuilder.Append("<td rowspan='" + len + "'>");
                        sbuilder.Append(drRow["Shift"].ToString() + "</td>");
                }
                sbuilder.Append("<td>" + drRow["FabricationType"].ToString() + "</td>");
                sbuilder.Append("<td>" + drRow["Stage"].ToString() + "</td>");
                
                sbuilder.Append("</tr>");
            }

            sbuilder.Append("</table>");
            //sbuilder.Append("<p> Thanks & Regards, <p>");
            //sbuilder.Append("<p>" + uname1 + "</p>");
            sbuilder.Append("</body></html>");
            return sbuilder.ToString();

        }


In this date is getting merged and it is showing only only one date, but not different dates.

Regards,
Avinash G.
Posted
Updated 14-Apr-14 18:58pm
v2

This is happening because you are only adding single token value. so, when the row with same token is iterated it doesn't add a td for your date value

<pre>  
                if (strToken != drRow["TokenNo"].ToString()) // this line won't allow row with same token to be included in your table
                {
                      strToken = drRow["TokenNo"].ToString();
                      strDate = drRow["Date"].ToString();
                       .......
                }



If you want to concatenate all dates for the same token iterate the rows with same token and create a string with all dates.
 
Share this answer
 
Comments
gavinash82 21-Apr-14 13:53pm    
Yes, i need that only. Because for every line this common data is getting repeated. So i've displaying the common data only once. Remaing are displayed normally.

But actually what i need is the date column should not get merged.

For example :
If I generate the report for 2 or more days, the date column is showing only the first date.

So now I need to check both Token Number and Date. If the Token Number is same, it should display only once and same as with the date as well.

Can you please guide me what i can do here.
Varsha Ramnani 30-Apr-14 10:45am    
Can you give sample of the output you need..
Yes, i need that only. Because for every line this common data is getting repeated. So i've displaying the common data only once. Remaing are displayed normally.

But actually what i need is the date column should not get merged.

For example :
If I generate the report for 2 or more days, the date column is showing only the first date.

So now I need to check both Token Number and Date. If the Token Number is same, it should display only once and same as with the date as well.

Can you please guide me what i can do here.
 
Share this answer
 

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