• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1976
  • Last Modified:

ASP.NET 2.0 GridView Delete Row

Hi

I have a gridview, objectdatasource, a class and an XML file containing data. The select and insert statements work fine, but I cannot get the delete statement to work. How do I pass the row number from the gridview to the class?

0
riffrack
Asked:
riffrack
  • 3
  • 2
1 Solution
 
Christopher KileCommented:
How is your delete statement structured?  The row number is unimportant unless it is the key of the row you want to delete.
0
 
riffrackAuthor Commented:
       Public Sub DeleteAuthor(ByVal row_id As Integer)
            dsAuthors.Tables(0).Rows(row_id).Delete()
            dsAuthors.WriteXml(filePath, Data.XmlWriteMode.WriteSchema)
        End Sub
0
 
Christopher KileCommented:
You don't get a row number passed to you - you get the primary key of the data row passed to you.  See this link:

http://www.codeproject.com/aspnet/GridViewConfirmDelete.asp

0
 
riffrackAuthor Commented:
hi

thanks for this link. I had a look and i still can't quite figure this out.

my gridview is attached to an objectdatasource control, this calls a class in the app_code folder, which stores the business layer. The data is stored in an XML file and the data does not contain a primary key.

any more ideas?
0
 
Christopher KileCommented:
Your business layer should then provide a unique key for each record (say, increment an integer from 1 to however many records you have in your XML file, then pass that integer as an additional column of the records you supply to the ObjectDataSource when a Select request is made of it.  It is the capable to do things like this that must have made you decide to use ObjectDataSource instead of XMLDataSource in the first place (I assume).

Do you understand what I'm saying?:
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now