Newbie: DeleteCommand not working.

Discussion in 'ASP .Net Datagrid Control' started by tuxedo, Aug 22, 2003.

  1. tuxedo

    tuxedo Guest

    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
     
    tuxedo, Aug 22, 2003
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter Afonin
    Replies:
    2
    Views:
    471
    Peter Afonin
    Nov 19, 2003
  2. Nathan Sokalski
    Replies:
    4
    Views:
    3,566
    Nathan Sokalski
    May 21, 2006
  3. jobs
    Replies:
    0
    Views:
    1,530
  4. Nathan Sokalski

    DataList.DeleteCommand event is not getting fired

    Nathan Sokalski, May 21, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    4
    Views:
    258
    Nathan Sokalski
    May 21, 2006
  5. Nathan Sokalski

    DataList.DeleteCommand event is not getting fired

    Nathan Sokalski, May 21, 2006, in forum: ASP .Net Web Controls
    Replies:
    4
    Views:
    166
    Nathan Sokalski
    May 21, 2006
Loading...

Share This Page