this is where the error stated :-
Source Error:
Line 131: approve = e.Item.Cells(6).Controls(0)
Line 132: approve = e.Item.FindControl("Label1")
Line 133: approve = CType(e.Item.Cells(6).Controls(0), ListBox).SelectedItem.Value
Line 134:
Line 135: approve = CType(e.Item.FindControl("Label1"), Label).Text
Source File: c:\inetpub\wwwroot\TimeManagement\WebForm5.aspx.vb Line: 133
Stack Trace:
[InvalidCastException: Specified cast is not valid.]
TimeManagement.WebForm5.dgUserAttendance_Update(Object sender, DataGridCommandEventArgs e) in c:\inetpub\wwwroot\TimeManagement\WebForm5.aspx.vb:133
System.Web.UI.WebControls.DataGrid.OnUpdateCommand(DataGridCommandEventArgs e)
System.Web.UI.WebControls.DataGrid.OnBubbleEvent(Object source, EventArgs e)
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
System.Web.UI.WebControls.DataGridItem.OnBubbleEvent(Object source, EventArgs e)
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e)
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()
------------------------------------------
n this is my exact code
Sub dgUserAttendance_Update(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
determine the value of the StaffID column
Dim name As String = e.Item.Cells(1).Text
Dim accessDate As String = e.Item.Cells(0).Text
refrence textbox
Dim approve As String
Dim dataGridItem As DataGridItem
approve = e.Item.Cells(6).Controls(0)
approve = e.Item.FindControl("Label1")
\***************************************
the error is in this line................
approve = CType(e.Item.Cells(6).Controls(0), ListBox).SelectedItem.Value
\***********************************
approve = CType(e.Item.FindControl("Label1"), Label).Text
CType(e.Item.FindControl("Label2"), Label).Text
updateApprove(accessDate, name, approve)
dgApproveStaff.EditItemIndex = -1
dgApproveStaff.DataSource = getStaff()
dgApproveStaff.DataBind()
End Sub
Function GetApproval()
conn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=E:\database\AttendanceReport.mdb;")
myCommandApproval = New OleDbCommand("SELECT * from TableApproval", conn)
conn.Open()
Dim approvalReader As OleDbDataReader
approvalReader = myCommandApproval.ExecuteReader
Return approvalReader
approvalReader.Close()
conn.Close()
End Function
Public Sub ItemDataBound(ByVal sender As Object, ByVal e As DataGridItemEventArgs)
If (e.Item.ItemType = ListItemType.EditItem) Then
Dim drv As DataRowView
drv = e.Item.DataItem
Dim oldApproval As String
oldApproval = drv("Approval").ToString()
Dim ddl As ListBox = e.Item.FindControl("Approval")
ddl.SelectedIndex = ddl.Items.IndexOf(ddl.Items.FindByText(oldApproval))
End If
End Sub