Wrox Programmer Forums
|
ASP.NET 1.x and 2.0 Application Design Application design with ASP.NET 1.0, 1.1, and 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.x and 2.0 Application Design 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 October 10th, 2007, 03:00 PM
Registered User
 
Join Date: Oct 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Deleting rows from a data table in datagrid

Hello, I am trying to delete a colum from a datatable which is displayed in a datagrid. when I excecute the code, it shows the error, there is no row at position 0(if i try to delete the first row, if 2nd row, it says "no rows at postion 2"). but I check the row.count method and it returns the number of rows in the table. still i get the error saying "there is no row at the corresponding postion. My code as follows

MyDatatable.aspx

<asp:DataGrid ID="Dg" runat="server" OnDeleteCommand ="Dg_DeleteCommand" >
        <Columns><asp:ButtonColumn CommandName="Delete" Text="Remove Item"></asp:ButtonColumn></Columns>

    </asp:DataGrid>

MyTable.aspx.vb(code behind file)

  Protected Sub Dg_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles Dg.DeleteCommand

objDT = Session("MyTable")
        Dim index As Integer
        If objDT.Rows.Count >= 0 Then
            index = objDT.Rows.Count
           objDT.Rows.Item(index).Delete()


        Else
            response.write("No rows in the tabel")

        End If
        Session("Mytable") = objDT
        Dg.DataSource = objDT
        Dg.DataBind()
 
Old October 23rd, 2007, 06:23 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anubhav.kumar
Default

Hi

index = objDT.Rows.Count
objDT.Rows.Item(index).Delete()

should be

index = objDT.Rows.Count
objDT.Rows.Item(index-1).Delete()

Anubhav Kumar





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 in Winforms Datagrid livehed General .NET 0 May 4th, 2006 01:23 AM
Deleting Rows in an Editable Data Grid RichardP ASP.NET 1.0 and 1.1 Professional 2 March 1st, 2006 02:19 PM





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