Protected Sub dglogAbsences_ItemCommand(ByVal source As System.Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dglogAbsences.ItemCommand
If (e.CommandName = "Delete") Then
Dim strsql As String
dim dataindex as interger=(CInt(dglogAbsences.DataKeys(CInt(e.Item.ItemIndex))))
strsql = "Delete from PersonnelAbsences where personnelid=" &dataindex
Dim dh As DataHandler
dglogAbsences.DataSource = dh.ExecuteDML(strsql)
dglogAbsences.DataBind()
end sub
here I have to delte a row in datagrid. I am in my way to get the datakey of that row.
You first problem is that you haven't specified the DataKeyField property for the DataGrid.
The second problem is if you are using version 2.0 of the framework, you shouldn't be using a DataGrid control anyway. This has been superceded by the improved GridView control.
hey all
If I assign datakeyfield as AbsenceID its giving this error
ERROR:A field or property with the name 'AbsenceID ' was not found on the selected data source.
But the datasource dgresult at 1 has the column AbsenceID and the method which it is calling i.e GetLogAbsences
has this query
Query
SELECT AbsenceID, Reason, Comments, convert("varchar",AbsenceStartDate,101)
as AbsenceStartDateDisp, convert("varchar",AbsenceEndDate,101) as AbsenceEndDateDisp
FROM PersonnelAbsences WHERE personnelID= 66 ORDER BY AbsenceStartDate
Datagrid :
Private Sub FilllogAbsencesGrid()
Dim dh As New DataHandlerAdmin
Dim dsResults As DataSet
dglogAbsences.Visible = True
'--- Get sorted equipment list data & display results in data grid.
dsResults = dh.GetLogAbsences(selStaff.SelectedValue, Session("sortColumn"), Session("sortOrder"))------------------------1
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.