protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
19 {
20 //此是要判斷為DataRow才執行,因為GridView有Header,Footer...等
21 if (e.Row.RowType == DataControlRowType.DataRow)
22 {
23 //CommandField使用此方法
24 ((Button)e.Row.Cells[0].Controls[0]).Attributes.Add("onclick", "if(!window.confirm('確定要刪除嗎?')) return;");
25
26
27 //ButtonField使用此方法
28 ((Button)e.Row.Cells[1].Controls[0]).Attributes.Add("onclick", "if(!window.confirm('確定要刪除嗎?')) return;");
29
30
31 //TemplateField已經在.aspx使用 OnClientClick="return confirm('確定刪除嗎?')" 設定了
32 }
33 }

上面是C#的程式碼,
改為VB的程式碼的話就是底下這段:

Protected Sub GVPastCh_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GVPastCh.RowCreated
If e.Row.RowType = DataControlRowType.DataRow Then
Dim delbtn As Button = CType(e.Row.Cells(11).Controls(0), Button)
delbtn.Attributes.Add("onclick", "if(!window.confirm('確定要刪除嗎?')) return;")
End If
End Sub

Posted by romeogi1023 at 痞客邦 PIXNET Comments(0) Trackback(0) Hits(50)