p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > ASP.NET and ASP > Other ASP.NET > ASP.NET 1.x and 2.0 Application Design
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 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 October 10th, 2007, 04:00 PM
Registered User
 
Join Date: Oct 2007
Location: , , .
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()
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old October 23rd, 2007, 07:23 AM
Friend of Wrox
Points: 391, Level: 6
Points: 391, Level: 6 Points: 391, Level: 6 Points: 391, Level: 6
Activity: 2%
Activity: 2% Activity: 2% Activity: 2%
 
Join Date: Oct 2004
Location: New Delhi, India.
Posts: 106
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
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 in Winforms Datagrid livehed General .NET 0 May 4th, 2006 02: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
Before deleting rows of DataGrid, a confirm messag swadhinm ASP.NET 1.1 2 August 5th, 2005 03:57 AM
Deleting rows of datagrid and paging anana ASP.NET 1.1 2 April 6th, 2004 09:57 PM



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


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