看板 Visual_Basic 關於我們 聯絡資訊
請輸入專案類型(網站專案或者應用程式專案):網頁 我有寫一段code,這些code是當使用者按下DataGrid中的刪除鍵, 會跳出是否刪除的確認視窗,讓使用者選擇"確定"或"取消",確定 的話,才作Label2.Text = e.Item.Cells(2).Text這個動作 我的程式碼html部分: <Columns> <asp:TemplateColumn HeaderText="是否刪除"> <HeaderStyle Wrap="False"></HeaderStyle> <ItemStyle Wrap="False"></ItemStyle> <ItemTemplate> <asp:Button id="delBTN" Text="刪除" CommandName="del" Runat="server"> </asp:Button> </ItemTemplate> </asp:TemplateColumn> </Columns> 我的程式碼CodeBehind部分: Private Sub DataGrid1_ItemCommand(ByVal source As Object, ByVal e As System. Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.ItemCommand Dim btn As Button = e.Item.FindControl("delBTN") btn.Attributes.Add("OnClick", "return confirm('是否刪除?');") Label2.Text = e.Item.Cells(2).Text End Sub 但奇怪的是,我要在刪除按鈕上按第二次,才會跳出這個確認視窗,而且我按第一次時, Label2.Text = e.Item.Cells(2).Text 就會執行,而不是等使用者選"確定"後才執行 有人能教一下,這是什麼原因嗎? 謝謝了~~ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 219.87.151.2