p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Professional
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 28th, 2006, 11:24 AM
Registered User
 
Join Date: Feb 2006
Location: Bath, NE Somerset, United Kingdom.
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?


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old March 1st, 2006, 01:52 PM
Authorized User
Points: 24, Level: 1
Points: 24, Level: 1 Points: 24, Level: 1 Points: 24, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2005
Location: , , .
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old March 1st, 2006, 02:19 PM
Friend of Wrox
Points: 4,166, Level: 27
Points: 4,166, Level: 27 Points: 4,166, Level: 27 Points: 4,166, Level: 27
Activity: 12%
Activity: 12% Activity: 12% Activity: 12%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,328
Thanks: 0
Thanked 1 Time in 1 Post
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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

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 07:23 AM
Help me in deleting value from database and grid amit_mande@yahoo.com 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 10:02 AM
Chapter 8 - Editable Grid Not Working bsowards24 BOOK: Beginning ASP.NET 1.1 0 October 12th, 2004 06:09 PM



All times are GMT -4. The time now is 07:35 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc