Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Flow of logic building an html table string from a sorteddictionary

Posted on 2011-02-23
17
Medium Priority
?
381 Views
Last Modified: 2012-08-14
Hello
I am trying to build an html string for an html table from a sorted dictionary
So the sorted dictionary would have keyvaluepairs with the date as a key and sometext as a value.
I would have the first day starting the middle of the week, in this case I would like to populate the dates for the cells before this entry.
Rows will be a row of dates then a row of text corresponding to these dates
then another row of date then another row of text untill the whole dictionary entries are represented in the calendar.
How would I build this.
I would like to build a string representing this table
such as the following
<table><tr><tc>07-01-2011</tc><tc>08-03-2011</tc>.....
Please take a look at the attached document this is what I am expecting
Monday      Tuesday      Wednesday      Thursday      Friday
7-02-2011      08-02-2011      09-02-2011      10-02-2011      11-02-2011
      Some Text              Some text      
21-02-2011      22-02-2011      23-02-2011      24-02-2011      24-02-2011
                        Some Text
07-03-2011      08-03-2011      09-03-2011      10-03-2011      11-03-2011
            Some Text            
 template.doc
0
Comment
Question by:xav056
  • 8
  • 7
  • 2
17 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 34970433
I am not sure that I understand your requirement, but it sounds like you are looking for an implementation of an HtmlTextWriter.

C# HtmlTextWriter Use
http://www.dotnetperls.com/htmltextwriter
0
 
LVL 9

Author Comment

by:xav056
ID: 34971552
not really,
what I am looking for is how to draw the table, the algorithim of drawing the table given the above scenario
so teh attached template would be the result of a duictionary that only has 4 entries
With the following
key value pair
08-02-2011
11-02-2011
24-02-2011
09-03-2011
The algorithm should be able to create the table as in the attached template i.e populate 5 days a week in a calendar with empty values when no entry exists in the dictionary
0
 
LVL 9

Author Comment

by:xav056
ID: 34971561
key                         value pair
08-02-2011           Some Text from the Dictionary
11-02-2011           Some text
24-02-2011           Some text
09-03-2011           Some text
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 96

Expert Comment

by:Bob Learned
ID: 34971587
What does "drawing" the table mean?  The HtmlTextWriter, along with a StringBuilder can generate the HTML text in that layout with <table>, <tr>, and <td> elements.
0
 
LVL 9

Author Comment

by:xav056
ID: 34971694
this is what I am looking for basically the html string that will result in a table similar to the attached one, however my problem lies in figuring out the logic to build this string
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 34971736
Are you looking for a way to pivot the date values so that the align with the days of the week columns?  Are you looking for a way to determine the day of the week for a date?

Example:

    DayOfWeek dayOfWeek = DateTime.Now.DayOfWeek;
0
 
LVL 9

Author Comment

by:xav056
ID: 34971875
Basically the problem is
Given a dictionary with only 4 entries below
key                         value pair
08-02-2011           Some Text from the Dictionary
11-02-2011           Some text
24-02-2011           Some text
09-03-2011           Some text
How do I build a string that will display the table in the template?
Thank you
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 34972342
One possible solution would be to define a table matrix of data, with 5 columns for the day of week, and then fill the rows from the data.  Once you have the matrix, then you should be able to generate the HTML table fairly easy.
0
 
LVL 9

Author Comment

by:xav056
ID: 34975599
How would I do that, given the data above?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 34976415
Do you have anything started?  I usually prefer the "guided tour" approach, where a direction is given, and food-for-thought is provided, but not completely answering the question...
0
 
LVL 9

Author Comment

by:xav056
ID: 34992062
No, it not alot of code but I can't wrap my head around it
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 35008207
Can you show me what you have so far?
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 35021596
Based on my understanding, try this code



Dim sb As New StringBuilder
sb.Append("<table><tr><td>Monday</td><td>Tuesday</td><td>Wednesday</td><td>Thursday</td><td>Friday</td></tr>")

For i As Integer = 0 to 5
   sb.Append("<tr>")
   For j As Integer = 0 to 4
      sb.Append("<td>").Append(Today.AddDays(j).tostring("dd/MM/yyyy")).Append("</td>")  
   Next
   sb.Append("</tr>")
   For j as Integer = 0 to 4
      If Dict.ContainsKey("key") Then
         sb.Append("<td>" & Dict.Item("key") & "</td>")
      Else
         sb.Append("<td></td>")
      End If
   Next
   sb.Append("</tr>")
Next
sb.Append("</table>")

Open in new window

0
 
LVL 9

Author Comment

by:xav056
ID: 35060890
Code cruiser,
This is close but not exactly what I am looking for
My dictionary does not have consecutive entry for the days, i.e it might have march 1,4 ,8,22 and that is it
my generated calendar should have 3 rows and it be able to populate the right days in the 1st row
thank you
0
 
LVL 9

Author Comment

by:xav056
ID: 35060901
by the way my dictionary key is the date and my value is what comes in the cell directly underneath that key
thank you
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 1200 total points
ID: 35070667
You need to put the data into piles, before you do any table creation, so that it is simple loops for the days and the rows.  You can declare different structures for the collection mechanism--such as a two-dimensional array for (days, rows), or an array of generic string lists.  You can loop through the data, to determine which column (day) the data needs to be added to.
0
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 800 total points
ID: 35132677
What I posted is conceptual code which can be modified. As TLO said above, you need to get the values in collections/lists and then its simple looping through the data.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Integration Management Part 2
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

963 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