View Single Post
  #1 (permalink)  
Old August 23rd, 2008, 06:17 PM
mii2029 mii2029 is offline
Authorized User
 
Join Date: Apr 2008
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default Dynamic control onclick event

I wrote the code below to populate a table with all open service requests from a database. If there are 2 open requests only two table rows are generated; if there are 20 open requests 20 rows are generated. That part is working perfectly fine. What is supposed to happen is when the user clicks on one of the images (imgStatus(i)) another window opens with the details of that request. Currently, the new window opens, but only the last item in the table is ever displayed, regardless of which image is clicked.

The onclientclick event will not capture the ID of the image that was clicked. Does anyone know how I can make the code recognize the clicked image and pick up its ID so the correct request can be displayed in the new window?

Thanks,

Dim conn As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirector y|\TSR.mdf;Trusted_Connection=True;User Instance=True")
        Dim SearchTSR As String = "SELECT TSRNumber, Request, Comments, ActionDTG, LastUser, Status FROM TSR WHERE Status BETWEEN 0 AND 4"
        Dim daSearchTSR As New SqlDataAdapter(SearchTSR, conn)
        Dim dsSearchTSR As New DataSet

        'Create a dataset for the matching entry
        daSearchTSR.Fill(dsSearchTSR, "dtSearchTSR")

        Dim totalrows As Integer = dsSearchTSR.Tables(0).Rows.Count
        'MsgBox(totalrows)
        'Exit Sub

        Dim imgStatus(0 To totalrows) As ImageButton
        Dim txtTsrNumber(0 To totalrows) As TextBox
        Dim tr(0 To totalrows) As TableRow

        'Display open TSRs
        If dsSearchTSR.Tables(0).Rows.Count = 0 Then
            MsgBox("There are no open TSRs at this time.", , "Technical Services")
            Response.Write("<script language='javascript'>")
            Response.Write("self.close()")
            Response.Write("</script>")
        Else
            Dim row1 As DataRow
            Dim i As Integer = 0
            For Each row1 In dsSearchTSR.Tables("dtSearchTSR").Rows
                tr(i) = New TableRow()
                Dim td1 As TableCell = New TableCell() 'Creates column 1

                td1.BorderStyle = BorderStyle.Solid
                td1.BorderWidth = 2
                td1.HorizontalAlign = HorizontalAlign.Center
                td1.VerticalAlign = VerticalAlign.Middle
                td1.Width = 150

                imgStatus(i) = New ImageButton()
                imgStatus(i).ID = "ImgStatus" & i
                imgStatus(i).CssClass = "panel control"
                imgStatus(i).ImageAlign = ImageAlign.Middle
                imgStatus(i).BorderStyle = BorderStyle.Solid
                imgStatus(i).BorderWidth = 1
                imgStatus(i).BorderColor = System.Drawing.ColorTranslator.FromHtml("#b3aaa1")
                imgStatus(i).Width = 100
                imgStatus(i).OnClientClick = "javascript:window.open('Review.aspx');"

                Dim lblStatus As Label = New Label()
                lblStatus.ID = "lblStatus" & i
                lblStatus.BorderStyle = BorderStyle.Solid
                lblStatus.BorderWidth = 1
                lblStatus.BorderColor = System.Drawing.ColorTranslator.FromHtml("#b3aaa1")
                lblStatus.CssClass = "table status label"
                lblStatus.Font.Bold = True

                Select Case row1("Status")
                    Case 0
                        imgStatus(i).ImageUrl = "~\Images\zero.bmp"
                        lblStatus.Text = "Not Yet Actioned"
                    Case 1
                        imgStatus(i).ImageUrl = "~\Images\25done.bmp"
                        lblStatus.Text = "Sent to SE"
                    Case 2
                        imgStatus(i).ImageUrl = "~\Images\50done.bmp"
                        lblStatus.Text = "Working"
                    Case 3
                        imgStatus(i).ImageUrl = "~\Images\50done.bmp"
                        lblStatus.Text = "Awaiting Info"
                    Case 4
                        imgStatus(i).ImageUrl = "~\Images\75done.bmp"
                        lblStatus.Text = "Dispositioned"
                End Select

                Dim td2 As TableCell = New TableCell 'Creates column 2
                td2.BorderStyle = BorderStyle.Solid
                td2.BorderWidth = 2
                td2.HorizontalAlign = HorizontalAlign.Left
                td2.VerticalAlign = VerticalAlign.Top
                td2.Width = 650

                Dim lblTsrNumber As Label = New Label
                lblTsrNumber.ID = "lblTsrNumber" & i
                lblTsrNumber.Width = 70
                lblTsrNumber.CssClass = "table top label"
                lblTsrNumber.Text = "TSR No:"

                txtTsrNumber(i) = New TextBox
                txtTsrNumber(i).ID = "txtTsrNumber" & i
                txtTsrNumber(i).Width = 100
                txtTsrNumber(i).CssClass = "table top control"
                txtTsrNumber(i).ReadOnly = True
                txtTsrNumber(i).Text = row1("TSRNumber")
                Session.Add("TSRNumber", txtTsrNumber(i).Text)
                imgStatus(i).ToolTip = txtTsrNumber(i).Text

                Dim lblLastAction As Label = New Label
                lblLastAction.ID = "lblLastAction" & i
                lblLastAction.Width = 100
                lblLastAction.CssClass = "table top label"
                lblLastAction.Text = "Last Actioned:"

                Dim txtLastAction As TextBox = New TextBox
                txtLastAction.ID = "txtLastAction" & i
                txtLastAction.Width = 125
                txtLastAction.CssClass = "table top control"
                txtLastAction.ReadOnly = True
                txtLastAction.Text = row1("ActionDTG")

                Dim lblBy As Label = New Label
                lblBy.ID = "lblBy" & i
                lblBy.Width = 25
                lblBy.CssClass = "table top label"
                lblBy.Text = "by:"

                Dim txtLastPerson As TextBox = New TextBox
                txtLastPerson.ID = "txtLastPerson" & i
                txtLastPerson.Width = 150
                txtLastPerson.CssClass = "table top control"
                txtLastPerson.ReadOnly = True
                'txtLastPerson.Text = row1("LastUser")

                Dim lblRequest As Label = New Label
                lblRequest.ID = "lblRequest" & i
                lblRequest.Width = 70
                lblRequest.CssClass = "label request"
                lblRequest.Text = "Request:"

                Dim txtRequest As TextBox = New TextBox
                txtRequest.ID = "txtRequest" & i
                txtRequest.Width = 530
                txtRequest.TextMode = TextBoxMode.MultiLine
                txtRequest.CssClass = "panel control"
                txtRequest.ReadOnly = True
                txtRequest.Text = row1("Request")

                Dim lblComments As Label = New Label
                lblComments.ID = "lblComments" & i
                lblComments.Width = 70
                lblComments.CssClass = "label comments"
                lblComments.Text = "Comments:"

                Dim txtComments As TextBox = New TextBox
                txtComments.ID = "txtComments" & i
                txtComments.Width = 530
                txtComments.Height = 80
                txtComments.TextMode = TextBoxMode.MultiLine
                txtComments.CssClass = "panel control"
                txtComments.ReadOnly = True
                If IsDBNull(row1("Comments")) Then
                    txtComments.Text = ""
                Else
                    txtComments.Text = row1("Comments")
                End If

                td1.Controls.Add(imgStatus(i)) 'These two lines define the fields in column 1
                td1.Controls.Add(lblStatus)

                td2.Controls.Add(lblTsrNumber) 'These lines define the fields in column 2
                td2.Controls.Add(txtTsrNumber(i))
                td2.Controls.Add(lblLastAction)
                td2.Controls.Add(txtLastAction)
                td2.Controls.Add(lblBy)
                td2.Controls.Add(txtLastPerson)
                td2.Controls.Add(lblRequest)
                td2.Controls.Add(txtRequest)
                td2.Controls.Add(lblComments)
                td2.Controls.Add(txtComments)

                tr(i).Cells.Add(td1) 'These lines add the columns to the row, then the row to the table
                tr(i).Cells.Add(td2)
                Table1.Rows.Add(tr(i))
                i = i + 1
            Next

        End If