Solved

Flow of logic building an html table string from a sorteddictionary

Posted on 2011-02-23
17
365 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
 
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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 300 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 200 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Encryption Decryption in Oracle 12 60
asp.net bundle 8 36
LINQ question 7 22
bulid json format 3 17
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now