Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 382
  • Last Modified:

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
0
xav056
Asked:
xav056
  • 8
  • 7
  • 2
2 Solutions
 
Bob LearnedCommented:
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
 
xav056Author Commented:
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
 
xav056Author Commented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Bob LearnedCommented:
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
 
xav056Author Commented:
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
 
Bob LearnedCommented:
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
 
xav056Author Commented:
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
 
Bob LearnedCommented:
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
 
xav056Author Commented:
How would I do that, given the data above?
0
 
Bob LearnedCommented:
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
 
xav056Author Commented:
No, it not alot of code but I can't wrap my head around it
0
 
Bob LearnedCommented:
Can you show me what you have so far?
0
 
CodeCruiserCommented:
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
 
xav056Author Commented:
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
 
xav056Author Commented:
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
 
Bob LearnedCommented:
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
 
CodeCruiserCommented:
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 8
  • 7
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now