Velocity Reviews

Velocity Reviews (
-   ASP .Net Datagrid Control (
-   -   Newbie: DeleteCommand not working. (

tuxedo 08-22-2003 12:00 AM

Newbie: DeleteCommand not working.
Hi, Gurus,
I am new to .net.
My problem is I am using Datagrid control in my first 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
The Dispaly has no problems,but I just can not get the DeleteCommand
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"
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
drDEP = dsDEP.Tables("AP").NewRow()
drDEP("Department_ID") = ""
dsDEP.Tables("AP").Rows.InsertAt(drDEP, 0)
grdDepartment.EditItemIndex = 0
grdDepartment.DataSource = dsDEP

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

.DataSource = dsDEP
End With
End If

End Sub

Private Sub grdDepartment_DeleteCommand(ByVal source As Object, ByVal
e As System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
lblTest.Text = e.Item.ItemIndex

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!!


All times are GMT. The time now is 01:16 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.