OndeleteCommand = "MyDataGrid_delete" DataKeyfield = "Title" AutoGenerateColumns = "false">
itemtemplate>
asp: templateColumn>
Itemtemplate>
asp: templateColumn>
Columns>
ask: DataGrid>
form>
body>
Html>
code:
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 Sub
Private sub page_init (Byvale as system.Object, byval e as system.eventargs) _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)
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