Results 1 to 5 of 5

Thread: Unable to delete record from gridview in C#

  1. #1
    Join Date
    Nov 2009
    Posts
    33

    Unable to delete record from gridview in C#

    Hello to all,
    I am new to this forum. I am working on project which is part of my syllabus. I am using C# language. I create gridview in my program. I able to add record to it, but unable to delete record from gridview . Whenever I click on delete link in the gridview I get 'can't cast object of type 'ASP.WForm1_aspx' to type "system.W.UI.WControls.GridviewRow'. I don't know what is that mean. Please help me.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Unable to delete record from gridview in C#

    Hey you need to use Explicit conversions to fix this problem. Explicit conversions must requires a cast operator to fix this problem. As per my knowledge source and destination variables are very much compatible, but there is one problem. There is a high risk of information loss because the type of the destination variable is a smaller in size than the source variable.
    In this case you have to use following variable in your program.
    Gridview gv2 = (Gridview)sS!

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: Unable to delete record from gridview in C#

    Code:
    class Test
    {
    static void Main()
    {
    double p = 4561.7;
    int w;
    // Cast double to int.
    w = (int)p;
    System.Console.WriteLine(w);
    }
    }
    // Output: 4561

    As like above example you have to use cast operator to fix this problem. You can do this in following ways.

    Cast 'System.Web.UI.WebControls.GridviewRow'

    GridView GRP=(GridView)SE;




    Hi,

    Try to type cast 'System.Web.UI.WebControls.GridviewRow'

    GridView grd=(GridView)sender;
    //type your code//

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Unable to delete record from gridview in C#

    As per my knowledge sender object is Gridview object and you have to cast it to GridView type in following ways.
    GridView GRP=(GridView)SE
    After this you have to get GridViewRow object by writing in following ways.
    GridViewRow DR = this.GridView1.Rows[e.RI];
    Now you will able to delete record from gridview.

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: Unable to delete record from gridview in C#

    Have you check that deleteRecordFromServer method is being called by setting a breakpoint in there? And that RecordToDelete is being set correctly? If all these thing set wrong then first make correction in it. After that look at the 'watch' values for 'sender' and 'viewGrid'. Now see what kind of objects they are and what values they hold. Sometimes what happened that you have to traverse the object hierarchy in the GridVied control to get to the right object.

Similar Threads

  1. Unable to record streaming audio
    By GOOL in forum Technology & Internet
    Replies: 4
    Last Post: 24-12-2010, 06:52 AM
  2. iPhone 4g is unable to record video
    By Eddu in forum Portable Devices
    Replies: 4
    Last Post: 10-11-2010, 03:19 PM
  3. Delete record from a java interface
    By Gunner 1 in forum Software Development
    Replies: 5
    Last Post: 19-01-2010, 10:56 AM
  4. Access: delete a record and insert it in another tab
    By Wguy2008 in forum Software Development
    Replies: 5
    Last Post: 02-04-2009, 11:24 PM
  5. Delete this record when it becomes stale
    By Magnus Kirkerud in forum Windows Server Help
    Replies: 1
    Last Post: 19-04-2007, 09:32 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,064,457.56412 seconds with 16 queries