0

我需要创建一个表,其第一列是一个图像按钮,单击时会删除整行(实际上它会删除数据库行然后重新加载 HTML 表)。

表格和按钮按预期显示,但是当我单击按钮时,没有任何反应。

为了使每个按钮都可点击,我使用了AddHandler.

删除是处理点击的子程序,它将获取按钮的 ID(其中包含用户要删除的行的数据库表 ID),然后以 ID 作为参数调用存储过程,最后重新加载 HTML 表。我还没有实现它,但调试器无法访问它。

VB代码如下

    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
    If Request.Cookies("myuser") Is Nothing OrElse Request.Cookies("myuser")("isconnected") <> "1" Then
        Response.Redirect("/Default.aspx")
    Else
        N_User = CInt(Request.Cookies("myuser")("N_User"))
        Dim dbc As DBConnection 
        dbc = New DBConnection("192.168.1.45", "CorpDB", "someuser", "xxxxxxx")
        Dim dt As DataTable
        Try
            dt = dbc.getQueryData("select lastname, isnull(firstname,'') from itc where N_User=" & CStr(N_User))
            If dt.Rows.Count > 0 Then
            End If
        Catch ex As Exception
            ' do nothing for now
        End Try
    End If
    FillTable()
End Sub


Protected Sub deletion(sender As Object, e As ImageClickEventArgs)
    ' confirm deletion
    ' Run a stored procedure to delete the comment row
    FillTable()
End Sub

Private Sub FillTable()
    Dim dbc As DBConnection
    Dim dt As DataTable
    Dim tr As TableRow
    Dim tc As TableCell
    Dim ibutton As ImageButton
    Dim sqlquery As String
    If PickProject.SelectedValue = "" Then
        Exit Sub
    End If
    sqlquery = "select N_follow, Name=isnull(isnull(lastname + ' ','') + Nom, 'Anon'), Date=convert(varchar,DFollow,103), Stage=isnull(FreeField1,''), [Text]=isnull(dbo.RTFtoText(txt),'') from AF_FOLLOW a left outer join USERS u on u.N_User = a.N_User_Create where Numero=" & PickProject.SelectedValue & "order by DFollow desc"
    dbc = New DBConnection("192.168.1.45", "CorpDB", "someuser", "xxxxxxx")
    Try
        dt = dbc.getQueryData(sqlquery)
    Catch ex As Exception
        ' Show something,
        Exit Sub
    End Try

    If dt.Rows.Count > 0 Then
        CommentTable.Rows.Clear()
        For Each row As DataRow In dt.Rows
            ' Create a new row
            tr = New TableRow

            ' column #1 : delete button
            tc = New TableCell
            tc.CssClass = "SelectDel"
            ibutton = New ImageButton()

            ibutton.ID = "ibutton_" & row.Item("N_follow")
            ibutton.ImageUrl = "img/remove_icon.png"
            AddHandler ibutton.Click, AddressOf deletion
            tc.Controls.Add(ibutton)

            tr.Cells.Add(tc)

            ' Column #2 : Date
            tc = New TableCell
            tc.Text = row.Item("Date")
            tr.Cells.Add(tc)

            ' Column #3 : Stage
            tc = New TableCell
            tc.Text = row.Item("Stage")
            tr.Cells.Add(tc)

            ' Column #4 : name
            tc = New TableCell
            tc.Text = row.Item("Name")
            tr.Cells.Add(tc)

            ' Column #5 : Comment
            tc = New TableCell
            tc.Text = row.Item("Text")
            tr.Cells.Add(tc)

            ' Add the created row to the table
            CommentTable.Rows.Add(tr)
        Next
        CommentTable.Visible = True
    Else
    End If
End Sub

出于某种原因,Page_Load当我单击按钮时会触发它。但是我得到了与 a 相同的行为DropDownList,首先Page_Load被触发,然后PickProject_SelectedIndexChanged事件处理程序按预期工作。

我用谷歌搜索了很多 StackOverflow,但建议的解决方案似乎都不起作用。

我错过了什么 ?

4

0 回答 0