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