Do not use on any
shared computer
July 24, 2008 07:47pm pdt
null
[x]
Attachment Details

Error when deleting row in Gridview using GridViewDeleteEventArgs when field is GUID

I've created a gridview listing various documents that have been uploaded to a documents folder on the server.  I have a delete button at the end of the gridview.  When I delete the row I want to delete the associated document.  In order to do this i am using the Gridview Rowdeleteing event: Below is as far as I have gotten in trying to identify the filename from the gridview:

Sub gvdoclist_RowDeleting(ByVal sender As Object, ByVal e As GridViewDeleteEventArgs)

        ' Get the file name of the file being deleted.

        Dim row As GridViewRow = gvDoclist.Rows(e.RowIndex)
        Dim FileNameId As String = row.Cells(2).Text
    End Sub

The stored file name is a GUID that matches the file name in my document folder.  When I click delete I get the following error:

System.InvalidCastException was unhandled by user code
  Message="Unable to cast object of type 'System.Guid' to type 'System.Web.UI.WebControls.GridViewRow'."
  Source="App_Web_kj42myet"
  StackTrace:
       at AdminDocs.gvdoclist_RowDeleting(Object sender, GridViewDeleteEventArgs e) in N:\SmallBusiness\MemberPages\AdminDocs.aspx.vb:line 547
       at System.Web.UI.WebControls.GridView.OnRowDeleting(GridViewDeleteEventArgs e)
       at System.Web.UI.WebControls.GridView.HandleDelete(GridViewRow row, Int32 rowIndex)
       at System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup)
       at System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source, EventArgs e)
       at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
       at System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source, EventArgs e)
       at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
       at System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e)
       at System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

It seems the system has an issue with the file value being a guid.  Any suggestions on how to capture the file name from the gridview row being deleted?  

Thanks in advance.

Ira
Start your free trial to view this solution
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Question Stats
Zone: Programming
Question Asked By: inewman
Solution Provided By: G0ggy
Participating Experts: 2
Solution Grade: B
Views: 19
Translate:
Loading Advertisement...
 
[+][-]Expert Comment by ajaysharmaapjs

Rank: Guru

Expert Comment by ajaysharmaapjs:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by G0ggy

Rank: Guru

Expert Comment by G0ggy:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by ajaysharmaapjs

Rank: Guru

Expert Comment by ajaysharmaapjs:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by inewman
Author Comment by inewman:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by inewman
Author Comment by inewman:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by inewman
Author Comment by inewman:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Accepted Solution by G0ggy

Rank: Guru

Accepted Solution by G0ggy:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
20080723-EE-VQP-34 / EE_QW_2_20070628