"CreateDate", "{0: YYYY-M-D}")%> '/>
Itemtemplate>
asp: templateColumn>
Columns>
ask: DataGrid>
form>
body>
Html>
Deleteit2.aspx.vb
Imports system
Imports system.Web
Imports system.data
Imports system.data.oledb
Imports System.Web.ui.WebControls
Public class deleteit2
Inherits System.Web.ui.page
Protected Withevents Label1 As System.Web.ui.WebControls.label
Protected withevents mydatagrid as system.web.ui.webcontrols.datagrid
#Region "The code" of the web form designer "
'This call is required for the web form designer.
private subinitializecomponent ()
End Subprivate Sub Page_init (Byval Sender As System.Object, ByVal E AS System.EventArgs)
Handles mybase.init
'Codegen: This method call is necessary for the web form designer
'Don't modify it using the code editor.
InitializeComponent ()
End Sub
#End region
Private sub page_load (byval sender as system.Object, byval e as system.eventargs) _EventArgs
Handles mybase.load
'Place the user code of the initialization page here
MyDataGrid.headerstyle.horizontalalign = horizontalalign.center
MyDataGrid.headerstyle.font.bold = true
MyDataGrid.headerstyle.backcolor = system.drawing.color.ivory
MyDataGrid.columns (0) .Headertext = "Operation"
MyDataGrid.columns (1) .Headertext = "Title"
MyDataGrid.columns (2) .Headertext = "Create Date"
IF not ispostback.
DIM STRCN As String = "provider = microsoft.jet.Oledb.4.0; data source =" _
Server.MAppath ("Test.mdb")
Dim strsql as string = "SELECT TOP 15 ObjectGuid, Title, Created" _
"From Document Order By CreateDate DESC"
DIM CN AS New OLEDBConnection (STRCN)
cn.open ()
DIM CMD AS New OLEDBCommand (strsql, cn)
MyDataGrid.dataSource = cmd.executeReader (Commandbehavior.CloseConnection)
MyDataGrid.Database
cmd.dispose ()
CMD = Nothing
cn.close ()
cn.dispose ()
CN = Nothing
END IF
End Sub
Public Sub DataGrid_Itemcreated (Byval Sender As Object, _
Byval e as system.web.ui.webcontrols.dataGriditemeventargs) Handles myDataGrid.Itemcreated
Select Case E.Item.ItemType
Case ListItemType.Item, ListItemType.AlternatingItem, ListItemType.editItem
DIM MyTablecell As TableCell
MyTableCell = E.Item.cells (0)
DIM MyDeletebutton as LinkButton
MyDeleteButton = MyTableCell.controls (0)
MyDeleteButton.attributes.add ("Onclick", "Return Confirm ('Do you really want to delete this row?');") mydeletebutton.text = "Delete this line"
End SELECT
End Sub
Sub MyDataGrid_Delete (Byval E AS DataGridCommandEventEventEventArgs)
Label1.text = "You want to delete: " _
myDataGrid.dataKeys (cint (e.Item.ItemIndex) " font>"
E.Item.BackColor = system.drawing.color.tomato
End Sub
END CLASS
Add confirmation deletion for DataGrid (3)
Add a confirmation deleted dialog box in DataGrid, the third method is to use the RegisteronSubmitState method for the Page object. The page.registeronSubmitStatement method enables the page to access the client onSubmit event. The script should be a function call to the client code to register elsewhere. The source code is as follows:
Deleteit3.aspx
<% @ Page language = "vb" autoeventwireup = "false" codebehind = "deteleit3.aspx.vb" inherits = "aspxweb.detleit3"%>