Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 28th, 2006, 11:24 AM
Registered User
 
Join Date: Feb 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Deleting Rows in an Editable Data Grid

I am having a problem trying to delete rows from an editable Data Grid. I have declared the grid as follows:-

<asp:datagrid id="DgSTDPE" runat="server" CssClass="datagrid" ShowHeader="False" SelectedItemStyle-BackColor="LightGreen"
                                    AutoGenerateColumns="False" DataKeyField="t_dsn" BorderColor="#000000">
                                    <EditItemStyle HorizontalAlign="Center" BackColor="LightGreen"></EditItemStyle>
                                    <Columns>
                                        <asp:BoundColumn DataField="t_dsn" ReadOnly="True" HeaderText="Demand Date DSN">
                                            <ItemStyle HorizontalAlign="Right" Width="100px"></ItemStyle>
                                            <FooterStyle HorizontalAlign="Center" VerticalAlign="Middle"></FooterStyle>
                                        </asp:BoundColumn>
                                        <asp:BoundColumn DataField="spc" ReadOnly="True" HeaderText="SPC">
                                            <ItemStyle HorizontalAlign="Right" Width="100px"></ItemStyle>
                                            <FooterStyle HorizontalAlign="Center" VerticalAlign="Middle"></FooterStyle>
                                        </asp:BoundColumn>
                                        <asp:BoundColumn DataField="dmc" ReadOnly="True" HeaderText="DMC">
                                            <ItemStyle HorizontalAlign="Right" Width="100px"></ItemStyle>
                                            <FooterStyle HorizontalAlign="Center" VerticalAlign="Middle"></FooterStyle>
                                        </asp:BoundColumn>
                                        <asp:BoundColumn DataField="nc" ReadOnly="True" HeaderText="NC">
                                            <ItemStyle HorizontalAlign="Left" Width="50px"></ItemStyle>
                                            <FooterStyle HorizontalAlign="Center" VerticalAlign="Middle"></FooterStyle>
                                        </asp:BoundColumn>
                                        <asp:BoundColumn DataField="iin" ReadOnly="True" HeaderText="IIN">
                                            <ItemStyle HorizontalAlign="Right" Width="180px"></ItemStyle>
                                            <FooterStyle HorizontalAlign="Center" VerticalAlign="Middle"></FooterStyle>
                                        </asp:BoundColumn>
                                        <asp:TemplateColumn HeaderText="QTY">
                                            <ItemTemplate>
                                                <asp:TextBox Runat=server ID="demand_qty" Text='<%# Container.DataItem("demand_qty") %>' />
                                            </ItemTemplate>
                                        </asp:TemplateColumn>
                                        <asp:BoundColumn DataField="locat" ReadOnly="True" HeaderText="DEPT">
                                            <ItemStyle HorizontalAlign="Left" Width="100px"></ItemStyle>
                                            <FooterStyle HorizontalAlign="Center" VerticalAlign="Middle"></FooterStyle>
                                        </asp:BoundColumn>
                                        <asp:BoundColumn DataField="task_no" ReadOnly="True" HeaderText="TASK">
                                            <ItemStyle HorizontalAlign="Left" Width="100px"></ItemStyle>
                                            <FooterStyle HorizontalAlign="Center" VerticalAlign="Middle"></FooterStyle>
                                        </asp:BoundColumn>
                                        <asp:BoundColumn DataField="rdd" ReadOnly="True" HeaderText="RDD" DataFormatString="{0:dd-MM-yy}">
                                            <ItemStyle HorizontalAlign="Left" Width="200px"></ItemStyle>
                                            <FooterStyle HorizontalAlign="Center" VerticalAlign="Middle"></FooterStyle>
                                        </asp:BoundColumn>
                                        <asp:BoundColumn DataField="dmd_type" ReadOnly="True" HeaderText="TYPE">
                                            <ItemStyle HorizontalAlign="Left" Width="60px"></ItemStyle>
                                            <FooterStyle HorizontalAlign="Center" VerticalAlign="Middle"></FooterStyle>
                                        </asp:BoundColumn>
                                        <asp:ButtonColumn Text="Delete" CommandName="Delete" />
</Columns>
</asp:datagrid></div>

I have got the VB program to update the database when I wish to write it back, but although I’ve added code to delete rows, I cannot get this to happen. My delete code is:-

Private Sub DgSTDPE_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles DgSTDPE.DeleteCommand
        Dim IntRowIndex As Integer
        Dim objTable As DataTable
        Dim objDelRow As DataRow ' the data row to be deleted
        IntRowIndex = e.Item.ItemIndex 'set IntRowIndex to the index value of the selected row.

        objTable = DataSet1.Tables("due_in")

        objTable.Rows(IntRowIndex).Delete()


        DgSTDPE.DataBind()

    End Sub



There error I get when a I click a delete button is:-


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 348: objTable = DataSet1.Tables("due_in")
Line 349:
Line 350: objTable.Rows(IntRowIndex).Delete() ‘this line is where the failure occurs
Line 351:
Line 352:

Source File: c:\inetpub\wwwroot\WebOASIS\STDPM Print Demands Menu\STDPE.aspx.vb Line: 350

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
   WebOASIS.STDPE.DgSTDPE_DeleteCommand(Object source, DataGridCommandEventArgs e) in c:\inetpub\wwwroot\WebOASIS\STDPM Print Demands Menu\STDPE.aspx.vb:350
   System.Web.UI.WebControls.DataGrid.OnDeleteCommand (DataGridCommandEventArgs e)
   System.Web.UI.WebControls.DataGrid.OnBubbleEvent(O bject source, EventArgs e)
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
   System.Web.UI.WebControls.DataGridItem.OnBubbleEve nt(Object source, EventArgs e)
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
   System.Web.UI.WebControls.LinkButton.OnCommand(Com mandEventArgs e)
   System.Web.UI.WebControls.LinkButton.System.Web.UI .IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument)
   System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
   System.Web.UI.Page.ProcessRequestMain()



--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573
Any ideas anyone?


 
Old March 1st, 2006, 01:52 PM
Authorized User
 
Join Date: Mar 2005
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

how is "DataSet1" defined.
what value are you getting for "IntRowIndex"?

 
Old March 1st, 2006, 02:19 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

The problem is you Dim statement:
Dim objTable As DataTable

You are not declaring it as a datatable in your dataset.

Check this example in the VSHelp:

ms-help://MS.VSCC.2003/MS.MSDNQTR.2006JAN.1033/dv_vbcode/html/vbtskCodeDeletingItemsInDataGridOrDataListWebContr olVisualBasic.htm






Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting multiple rows in data view or grid deepakbachelor SQL Server 2005 1 December 7th, 2007 02:19 PM
Deleting rows from a data table in datagrid ann03 ASP.NET 1.x and 2.0 Application Design 1 October 23rd, 2007 06:23 AM
Help me in deleting value from database and grid [email protected] ASP.NET 1.0 and 1.1 Basics 0 December 27th, 2006 02:43 AM
Field Validation in an Editable Data Grid Shadane ASP.NET 1.0 and 1.1 Basics 3 October 2nd, 2006 09:02 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.