470,631 Members | 1,713 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,631 developers. It's quick & easy.

Error when deleting record from a gridview

hi all,

I have this error when I click delete link in the gridview:

'unable to cast object of type 'ASP.WebForm1_aspx' to type "system.Web.UI.WebControls.GridviewRow'

I really need help as soon as possible :(
Dec 22 '09 #1
4 1561
sanjib65
102 100+
Explicit conversions (casts) require a cast operator. The source and destination variables are compatible, but there is a risk of data loss because the type of the destination variable is a smaller size than (or is a base class of) the source variable.

So you can try this:

Gridview gv = (Gridview)sender
//Your code here
Dec 22 '09 #2
what do u mean by sender?

my line is already casted to (GridviewRow).
Dec 22 '09 #3
sanjib65
102 100+
I hope this example will make the conception clear:

Expand|Select|Wrap|Line Numbers
  1. class Test
  2. {
  3.     static void Main()
  4.     {
  5.         double x = 1234.7;
  6.         int a;
  7.         // Cast double to int.
  8.         a = (int)x;
  9.         System.Console.WriteLine(a);
  10.     }
  11. }
  12. // Output: 1234
Dec 23 '09 #4
Dheeraj Joshi
1,123 Expert 1GB
'unable to cast object of type 'ASP.WebForm1_aspx' to type "system.Web.UI.WebControls.GridviewRow'
Basically you are trying to case form type to GridviewRow type.
Sanji told you to typecast it....

Use like this.

Expand|Select|Wrap|Line Numbers
  1. GridviewRow myGridRow = sender as GridviewRow;
  2.  
Regards
Dheeraj Joshi
Dec 23 '09 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

8 posts views Thread by Steve | last post: by
reply views Thread by RAllsopp | last post: by
reply views Thread by gr8beer | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.