Dataset and Dynamic Table

moc2469

Active member
Joined
Jun 21, 2007
Messages
27
Programming Experience
1-3
I am programming an app. that will be used to do Scheduling for employees. I am trying to fill a dynamic table on the page based on the returned dataset. I can display the first person and their associated times, but I get nothing for the rest.
VB.NET:
Public Function Setup_Page(ByVal myDS As DataSet)
        'Set var for dataset
        ds = myDS 'This is Public.....

        'Var used in For loop
        Dim x, i As Int32

        'Find number of employees to print on schedule
        iCount = ds.Tables(0).Rows.Count / 7 'Becaue each entry is name,       starttime, endtime, date

        'Page Title
        Response.Write("<table>")
        Response.Write("<tr><td style='FONT-SIZE: 24pt'><b>Company's Name</b></td>")
        Response.Write("<td width='150'></td>")
        Response.Write("<td style='FONT-SIZE: 18pt' colspan='2' align='center'><b>WEEKLY WORK SCHEDULE</b></td></tr>")
        Response.Write("<tr><td width='250'></td><td width='150'></td>")
        Response.Write("<td style='FONT-SIZE: 18pt' width='150'><b>Store: " & sStore & "</b></td>")
        Response.Write("<td style='FONT-SIZE: 18pt'><b>Week Ending: " & sTo & "</b></td></tr>")
        Response.Write("</table>")

        Dim dayOfWeek1, dayOfWeek2, dayOfWeek3, dayOfWeek4, dayOfWeek5, dayOfWeek6, dayOfWeek7 As Date
        Dim sdayOfWeek1, sdayOfWeek2, sdayOfWeek3, sdayOfWeek4, sdayOfWeek5, sdayOfWeek6, sdayOfWeek7 As String

        dayOfWeek1 = ds.Tables(0).Rows(x).Item("e_DATE")
        sdayOfWeek1 = dayOfWeek1.AddDays(0).DayOfWeek.ToString()
        dayOfWeek2 = ds.Tables(0).Rows(x + 1).Item("e_DATE")
        sdayOfWeek2 = dayOfWeek2.AddDays(0).DayOfWeek.ToString()
        dayOfWeek3 = ds.Tables(0).Rows(x + 2).Item("e_DATE")
        sdayOfWeek3 = dayOfWeek3.AddDays(0).DayOfWeek.ToString()
        dayOfWeek4 = ds.Tables(0).Rows(x + 3).Item("e_DATE")
        sdayOfWeek4 = dayOfWeek4.AddDays(0).DayOfWeek.ToString()
        dayOfWeek5 = ds.Tables(0).Rows(x + 4).Item("e_DATE")
        sdayOfWeek5 = dayOfWeek5.AddDays(0).DayOfWeek.ToString()
        dayOfWeek6 = ds.Tables(0).Rows(x + 5).Item("e_DATE")
        sdayOfWeek6 = dayOfWeek6.AddDays(0).DayOfWeek.ToString()
        dayOfWeek7 = ds.Tables(0).Rows(x + 6).Item("e_DATE")
        sdayOfWeek7 = dayOfWeek7.AddDays(0).DayOfWeek.ToString()

        'Create as many rows as needed then populate them
        Dim sName As String
        sName = ds.Tables(0).Rows(x).Item("e_EMPLOYEE")

        'Header Table
        Response.Write("<table id='myTable'" & x & " style='FONT-SIZE: 12pt'>")
        Response.Write("<tr><td style='BORDER-RIGHT: black thin solid; BORDER-TOP: black thin solid; BORDER-LEFT: black thin solid; BORDER-BOTTOM: black thin solid' width='200'><b>Name: " & sName & "</b></td>")
        Response.Write("<td style='BORDER-RIGHT: black thin solid; BORDER-TOP: black thin solid; BORDER-LEFT: black thin solid; BORDER-BOTTOM: black thin solid' width='100' align='center'><b>" & sdayOfWeek1 & "</b></td>")
        Response.Write("<td style='BORDER-RIGHT: black thin solid; BORDER-TOP: black thin solid; BORDER-LEFT: black thin solid; BORDER-BOTTOM: black thin solid' width='100' align='center'><b>" & sdayOfWeek2 & "</b></td>")
        Response.Write("<td style='BORDER-RIGHT: black thin solid; BORDER-TOP: black thin solid; BORDER-LEFT: black thin solid; BORDER-BOTTOM: black thin solid' width='100' align='center'><b>" & sdayOfWeek3 & "</b></td>")
        Response.Write("<td style='BORDER-RIGHT: black thin solid; BORDER-TOP: black thin solid; BORDER-LEFT: black thin solid; BORDER-BOTTOM: black thin solid' width='100' align='center'><b>" & sdayOfWeek4 & "</b></td>")
        Response.Write("<td style='BORDER-RIGHT: black thin solid; BORDER-TOP: black thin solid; BORDER-LEFT: black thin solid; BORDER-BOTTOM: black thin solid' width='100' align='center'><b>" & sdayOfWeek5 & "</b></td>")
        Response.Write("<td style='BORDER-RIGHT: black thin solid; BORDER-TOP: black thin solid; BORDER-LEFT: black thin solid; BORDER-BOTTOM: black thin solid' width='100' align='center'><b>" & sdayOfWeek6 & "</b></td>")
        Response.Write("<td style='BORDER-RIGHT: black thin solid; BORDER-TOP: black thin solid; BORDER-LEFT: black thin solid; BORDER-BOTTOM: black thin solid' width='100' align='center'><b>" & sdayOfWeek7 & "</b></td></tr>")
        Response.Write("</table>")

        'Set first row, first cell
        Dim row1 As DateTime = ds.Tables(0).Rows(0).Item("e_START")
        row1 = row1.ToShortTimeString()

        'Body Table
        Response.Write("<table id='dataTable'" & x & " style='FONT-SIZE: 12pt'>")
        Response.Write("<tr><td style='BORDER-RIGHT: black thin solid; BORDER-TOP: black thin solid; BORDER-LEFT: black thin solid; BORDER-BOTTOM: black thin solid' width='200' align='right'>")
        Response.Write("<b>Start:</b></td>")
        Response.Write("<td style='BORDER-RIGHT: black thin solid; BORDER-TOP: black thin solid; BORDER-LEFT: black thin solid; BORDER-BOTTOM: black thin solid' width='100' align='center'>")
        Response.Write(row1 & "</td>")

        'Seven days in the week
        For x = 1 To 7
            If ds.Tables(0).Rows(x).Item("e_EMPLOYEE") = ds.Tables(0).Rows(x - 1).Item("e_EMPLOYEE") Then
                Dim sTime1 As DateTime
                sTime1 = ds.Tables(0).Rows(x).Item("e_START")
                sTime1 = sTime1.ToShortTimeString()
                Response.Write("<td style='BORDER-RIGHT: black thin solid; BORDER-TOP: black thin solid; BORDER-LEFT: black thin solid; BORDER-BOTTOM: black thin solid' width='100' align='center'>")
                Response.Write(sTime1 & "</td>")
            End If
        Next x
        Response.Write("</tr>")

        'Set second row, cell 1
        Dim row2 As DateTime = ds.Tables(0).Rows(0).Item("e_FINISH")
        row2 = row2.ToShortTimeString()

        'Next Row
        Response.Write("<tr><td style='BORDER-RIGHT: black thin solid; BORDER-TOP: black thin solid; BORDER-LEFT: black thin solid; BORDER-BOTTOM: black thin solid' width='200' align='right'>")
        Response.Write("<b>Finish:</b></td>")
        Response.Write("<td style='BORDER-RIGHT: black thin solid; BORDER-TOP: black thin solid; BORDER-LEFT: black thin solid; BORDER-BOTTOM: black thin solid' width='100' align='center'>")
        Response.Write(row2 & "</td>")
        'Seven days in the week
        For x = 1 To 7
            If ds.Tables(0).Rows(x).Item("e_EMPLOYEE") = ds.Tables(0).Rows(x - 1).Item("e_EMPLOYEE") Then
                Dim sEnd1 As DateTime
                sEnd1 = ds.Tables(0).Rows(x).Item("e_FINISH")
                sEnd1 = sEnd1.ToShortTimeString()
                Response.Write("<td style='BORDER-RIGHT: black thin solid; BORDER-TOP: black thin solid; BORDER-LEFT: black thin solid; BORDER-BOTTOM: black thin solid' width='100' align='center'>")
                Response.Write(sEnd1 & "</td>")
            End If
        Next x
        Response.Write("</tr></table>")
    End Function

Any Ideas????????
 
Last edited by a moderator:
I would try to look further at the code but have you ever considered breaking it down into functions in a few loops so that it would be much easier to read.
It is hard to tell what is going on there without getting a headache and it is good programming practice to break those blocks of code into functions and loops.

I am sure if you clean it up a bit you will easily be able to tell where the hole is in your logic and why the dataset does not contain everything that you had hoped it would.
 
I know it is alot to look at. We have figured a way around this issue. I am using multiple arrays to get the info I need and then loop through them to print the neccessary data.

Thanks!!!!!
 
You should consider using server controls instead of writing code to generate Html tags. .Net 1.1 have for example DataGrid, Repeater and DataList controls for displaying data. Visual Studio IDE also let you set up the page in Design mode for other page elements.
 
It Depends on what they want

I cannot use any of those as I need a 'printer friendly' version of what I am displaying, that is the reason for the HTML. In the last two jobs I have had they both use HTML for output when printing dynamic information. That way you can format the look of your output.
 
I don't see why you can't use ASP.Net to generate the "printer-friendly" version of the page also? It all comes down to generated Html content anyway.
 
Not Sure

I'm not as familiar with ASP.NET as I would like to be. How would you do it then in ASP.NET?
 

Latest posts

Back
Top