Error when deleting record from a gridview

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Queen Soso
    New Member
    • Dec 2009
    • 13

    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_a spx' to type "system.Web.UI. WebControls.Gri dviewRow'

    I really need help as soon as possible :(
  • sanjib65
    New Member
    • Nov 2009
    • 102

    #2
    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)sende r
    //Your code here

    Comment

    • Queen Soso
      New Member
      • Dec 2009
      • 13

      #3
      what do u mean by sender?

      my line is already casted to (GridviewRow).

      Comment

      • sanjib65
        New Member
        • Nov 2009
        • 102

        #4
        I hope this example will make the conception clear:

        Code:
        class Test
        {
            static void Main()
            {
                double x = 1234.7;
                int a;
                // Cast double to int.
                a = (int)x;
                System.Console.WriteLine(a);
            }
        }
        // Output: 1234

        Comment

        • Dheeraj Joshi
          Recognized Expert Top Contributor
          • Jul 2009
          • 1129

          #5
          'unable to cast object of type 'ASP.WebForm1_a spx' to type "system.Web.UI. WebControls.Gri dviewRow'
          Basically you are trying to case form type to GridviewRow type.
          Sanji told you to typecast it....

          Use like this.

          Code:
          GridviewRow myGridRow = sender as GridviewRow;
          Regards
          Dheeraj Joshi

          Comment

          Working...