最初の列が、クリックすると行全体を削除する画像ボタンであるテーブルを作成する必要があります (実際には、データベース行を削除してから 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
、ボタンをクリックするとトリガーされます。しかし、私は で同じ動作を得てDropDownList
、最初Page_Load
に起動し、次にPickProject_SelectedIndexChanged
イベントハンドラーが意図したとおりに動作します。
私はグーグルでStackOverflowをたくさん検索しましたが、提案された解決策はどれもうまくいかないようです。
私は何を取りこぼしたか ?