M
Mark
Hi - I posted this in the ASP.Net forum, but have not had any help
unfortunately:
I am adding a 'gantt chart' style table, to manage peoples availability
- if they are unavailable, the table cell is just coloured - if they are
available (and therefore bookable), I add a link button control to the
table cell.
Trouble is, when I click on the link button, and it posts back to the
server, even although I call the sub to show populate the table from
page_load - it doesn't redraw the table.
I'd really appreciate any advice on where I'm going wrong - my code is
below:
<asp:table id="Table1" runat="server" BorderColor="Black"
BorderStyle="None" BorderWidth="1px" ForeColor="#F7F7F7"
BackColor="#4A3C8C" CellPadding="0" CellSpacing="1"
EnableViewState="False"></asp:table>
..and I add my control like this (first line deals with the persons name
and the dates, the rest is to either block off the table cell, or
provide the 'dynamic' control to be used in postback - however, when
someone clicks on the dynamically created link, even although I call
doDateArray from within Page_load, it does not show on the postback -
however, if I subsequently call the function again, it will appear - I
think it is to do with: AddHandler objBtn.Click, AddressOf btnClicked -
but if anyone could advise, I'd appreciate it.
Code which I think is being called by the dynamic control, and the
dynamic control are shown below.
Sub btnClicked(ByVal obj As Object, ByVal e As EventArgs)
doDateArray()
End Sub
Sub doDateArray()
Dim sDate As DateTime
Dim x As Integer
Dim myDateArr As ArrayList
sDate = calOverview.SelectedDate
myDateArr = New ArrayList
For x = 0 To 31
myDateArr.Add(sDate.AddDays(x).ToShortDateString.ToString)
Next
x = myDateArr.Count
Dim mystring As String
Dim mt_ConvDate As String
Dim bookingexists As Integer
Dim i As Integer
Dim mtr As New TableRow
Dim mtcresourcename2 As New TableCell
mtcresourcename2.Controls.Add(New LiteralControl("resource"))
mtr.Cells.Add(mtcresourcename2)
For i = 0 To x - 1
Dim mtc As New TableCell
Select Case CDate(myDateArr(i)).DayOfWeek
Case DayOfWeek.Saturday, DayOfWeek.Sunday
mtc.Controls.Add(New
LiteralControl(CDate(myDateArr(i)).Day))
Case Else
mtc.Controls.Add(New
LiteralControl(CDate(myDateArr(i)).Day))
End Select
mtc.Width = Unit.Pixel(22)
mtr.Cells.Add(mtc)
Next
Table1.Rows.Add(mtr)
Dim strConn As String =
ConfigurationSettings.AppSettings("conString")
Dim mysql As String = "SELECT resource_id, resource_name FROM
tblresource WHERE hotel_id=@hotel_id ORDER BY resource_name"
Dim myConn As New SqlConnection(strConn)
Dim objDR As SqlDataReader
Dim cmd As New SqlCommand(mysql, myConn)
cmd.Parameters.Add(New SqlParameter("@hotel_id", "" &
Session("Hotel_id")))
myConn.Open()
objDR = cmd.ExecuteReader(CommandBehavior.CloseConnection)
Dim resource_id As Integer
Dim resource_name As String
While objDR.Read()
resource_id = objDR("resource_id")
resource_name = objDR("resource_name")
Dim mtr2 As New TableRow
Dim mtcresourcename As New TableCell
mtcresourcename.Controls.Add(New LiteralControl("<div
style='background-color:Blue;color:white;'>" & resource_name &
"</div>"))
mtr2.Cells.Add(mtcresourcename)
For i = 0 To x - 1
Dim mtc2 As New TableCell
mt_ConvDate = mt_date(myDateArr(i))
bookingexists = checkBookingExist2(mt_ConvDate,
resource_id)
If bookingexists > 0 Then
mtc2.Controls.Add(New LiteralControl("<div
style='background-color:limegreen;color:white;'> </div>"))
Else
Dim objBtn As New LinkButton
objBtn.ID = "btnID" & resource_id.ToString & "_" &
i.ToString
objBtn.EnableViewState = False
objBtn.CausesValidation = False
objBtn.Text = "-"
AddHandler objBtn.Click, AddressOf btnClicked
mtc2.Controls.Add(objBtn)
mtc2.BackColor = System.Drawing.Color.White
mtc2.HorizontalAlign = HorizontalAlign.Center
mtc2.VerticalAlign = VerticalAlign.Middle
End If
mtr2.Cells.Add(mtc2)
Next
Table1.Rows.Add(mtr2)
End While
myConn.Close()
End Sub
unfortunately:
I am adding a 'gantt chart' style table, to manage peoples availability
- if they are unavailable, the table cell is just coloured - if they are
available (and therefore bookable), I add a link button control to the
table cell.
Trouble is, when I click on the link button, and it posts back to the
server, even although I call the sub to show populate the table from
page_load - it doesn't redraw the table.
I'd really appreciate any advice on where I'm going wrong - my code is
below:
<asp:table id="Table1" runat="server" BorderColor="Black"
BorderStyle="None" BorderWidth="1px" ForeColor="#F7F7F7"
BackColor="#4A3C8C" CellPadding="0" CellSpacing="1"
EnableViewState="False"></asp:table>
..and I add my control like this (first line deals with the persons name
and the dates, the rest is to either block off the table cell, or
provide the 'dynamic' control to be used in postback - however, when
someone clicks on the dynamically created link, even although I call
doDateArray from within Page_load, it does not show on the postback -
however, if I subsequently call the function again, it will appear - I
think it is to do with: AddHandler objBtn.Click, AddressOf btnClicked -
but if anyone could advise, I'd appreciate it.
Code which I think is being called by the dynamic control, and the
dynamic control are shown below.
Sub btnClicked(ByVal obj As Object, ByVal e As EventArgs)
doDateArray()
End Sub
Sub doDateArray()
Dim sDate As DateTime
Dim x As Integer
Dim myDateArr As ArrayList
sDate = calOverview.SelectedDate
myDateArr = New ArrayList
For x = 0 To 31
myDateArr.Add(sDate.AddDays(x).ToShortDateString.ToString)
Next
x = myDateArr.Count
Dim mystring As String
Dim mt_ConvDate As String
Dim bookingexists As Integer
Dim i As Integer
Dim mtr As New TableRow
Dim mtcresourcename2 As New TableCell
mtcresourcename2.Controls.Add(New LiteralControl("resource"))
mtr.Cells.Add(mtcresourcename2)
For i = 0 To x - 1
Dim mtc As New TableCell
Select Case CDate(myDateArr(i)).DayOfWeek
Case DayOfWeek.Saturday, DayOfWeek.Sunday
mtc.Controls.Add(New
LiteralControl(CDate(myDateArr(i)).Day))
Case Else
mtc.Controls.Add(New
LiteralControl(CDate(myDateArr(i)).Day))
End Select
mtc.Width = Unit.Pixel(22)
mtr.Cells.Add(mtc)
Next
Table1.Rows.Add(mtr)
Dim strConn As String =
ConfigurationSettings.AppSettings("conString")
Dim mysql As String = "SELECT resource_id, resource_name FROM
tblresource WHERE hotel_id=@hotel_id ORDER BY resource_name"
Dim myConn As New SqlConnection(strConn)
Dim objDR As SqlDataReader
Dim cmd As New SqlCommand(mysql, myConn)
cmd.Parameters.Add(New SqlParameter("@hotel_id", "" &
Session("Hotel_id")))
myConn.Open()
objDR = cmd.ExecuteReader(CommandBehavior.CloseConnection)
Dim resource_id As Integer
Dim resource_name As String
While objDR.Read()
resource_id = objDR("resource_id")
resource_name = objDR("resource_name")
Dim mtr2 As New TableRow
Dim mtcresourcename As New TableCell
mtcresourcename.Controls.Add(New LiteralControl("<div
style='background-color:Blue;color:white;'>" & resource_name &
"</div>"))
mtr2.Cells.Add(mtcresourcename)
For i = 0 To x - 1
Dim mtc2 As New TableCell
mt_ConvDate = mt_date(myDateArr(i))
bookingexists = checkBookingExist2(mt_ConvDate,
resource_id)
If bookingexists > 0 Then
mtc2.Controls.Add(New LiteralControl("<div
style='background-color:limegreen;color:white;'> </div>"))
Else
Dim objBtn As New LinkButton
objBtn.ID = "btnID" & resource_id.ToString & "_" &
i.ToString
objBtn.EnableViewState = False
objBtn.CausesValidation = False
objBtn.Text = "-"
AddHandler objBtn.Click, AddressOf btnClicked
mtc2.Controls.Add(objBtn)
mtc2.BackColor = System.Drawing.Color.White
mtc2.HorizontalAlign = HorizontalAlign.Center
mtc2.VerticalAlign = VerticalAlign.Middle
End If
mtr2.Cells.Add(mtc2)
Next
Table1.Rows.Add(mtr2)
End While
myConn.Close()
End Sub