Newbie: DeleteCommand not working.

T

tuxedo

Hi, Gurus,
I am new to .net.
My problem is I am using Datagrid control in my first ASP.net APP.
One page have 3 Datagrid on it and they want to save all grids
together with one SAVE!?
So I will have to update the Dataset one by one each time the grid
changes.
The Dispaly has no problems,but I just can not get the DeleteCommand
working.
Here is my Code, please Help!

'--------
Dim dsDEP As New DataSet()
Dim drDEP As DataRow

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If Not IsPostBack Then

'Populate DepartmentGrid
ViewState("AddingDEP") = "Off"
BindGridDEP()
m_DAl = Nothing
end if
end sub

Private Sub BindGridDEP()
Dim grd_DAL As New DataAccess()

'-----Bind grdDepartment
If ViewState("AddingDEP") = "On" Then
dsDEP = grd_DAL.GetDataSet("Select Department_ID from
Vendor_Department")
drDEP = dsDEP.Tables("AP").NewRow()
drDEP("Department_ID") = ""
dsDEP.Tables("AP").Rows.InsertAt(drDEP, 0)
grdDepartment.EditItemIndex = 0
grdDepartment.DataSource = dsDEP
grdDepartment.DataBind()
Else

With grdDepartment
dsDEP = grd_DAL.GetDataSet("Select Department_ID from
Vendor_Department")

.DataSource = dsDEP
.DataBind()
End With
End If


End Sub


Private Sub grdDepartment_DeleteCommand(ByVal source As Object, ByVal
e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
grdDepartment.DeleteCommand
lblTest.Text = e.Item.ItemIndex
!!!!!!!PROBLEM HERE
dsDEP.Tables("AP").Rows(e.Item.ItemIndex).Delete()

End Sub


I always get :
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object.

Source Error:

Line 365: dsDEP.Tables("AP").Rows(e.Item.ItemIndex).Delete()

I could probably put that Dataset-dsDEP in the viewstate which I did,
It will not be out of Scope( But Why???)
1. How can I gain access to the Dataset which is bound to the Grid
after DeleteCommand?
2. From my Code, is it the right way to get the index from the grid
and then delete the record from the DataTable?
3. Off topic question and could be stupid, Can I use Dataadpter.update
to update a data source which is populate by a stored-Procedure(
involved in fields in 3 tables?

Thank you very much!!

Tuxedo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top