Link to home
Start Free TrialLog in
Avatar of xav056
xav056

asked on

Flow of logic building an html table string from a sorteddictionary

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
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

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
Avatar of xav056
xav056

ASKER

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
Avatar of xav056

ASKER

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
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.
Avatar of xav056

ASKER

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
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;
Avatar of xav056

ASKER

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
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.
Avatar of xav056

ASKER

How would I do that, given the data above?
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...
Avatar of xav056

ASKER

No, it not alot of code but I can't wrap my head around it
Can you show me what you have so far?
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

Avatar of xav056

ASKER

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
Avatar of xav056

ASKER

by the way my dictionary key is the date and my value is what comes in the cell directly underneath that key
thank you
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial