By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,836 Members | 1,840 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,836 IT Pros & Developers. It's quick & easy.

Error when deleting record from a gridview

P: 13
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
Share this Question
Share on Google+
4 Replies

P: 102
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

P: 13
what do u mean by sender?

my line is already casted to (GridviewRow).
Dec 22 '09 #3

P: 102
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
Expert 100+
P: 1,123
'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;
Dheeraj Joshi
Dec 23 '09 #5

Post your reply

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