GridButtonColumn Delete button

5 posts, 0 answers
  1. Bob
    Bob avatar
    87 posts
    Member since:
    Jan 2008

    Posted 04 Apr 2008 Link to this post

    Hi all,

    I have radGrid and I added a Delete button.  When clicked, I want to fetch the DataKeyNames value and then delete the corresponding row in my sql table.  I already have the radgrid set-up and I also have a method to delete the row.  What I cannot figure out is how to get the value of the selected DataKeyNames.  I am trying this but it's not working:

    Dim

    iPolicyId As Integer = Convert.ToInt32((e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("PolicyId")))


    Any ideas on how I can get this value?

    Thanks,
    Bob

  2. Piyush Bhatt
    Piyush Bhatt avatar
    166 posts
    Member since:
    Nov 2007

    Posted 04 Apr 2008 Link to this post

    Bob,

    My Delete operation works as follows. May be you could try the same.

    -Piyush
    (Not telerik)

        protected void ActivityGrid_DeleteCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {
            GridEditableItem eitem = e.Item as GridEditableItem;
            Hashtable newValues = new Hashtable();
            eitem.OwnerTableView.ExtractValuesFromItem(newValues, eitem);      
            int id = Convert.ToInt32(newValues["ActivityID"]);
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Bob
    Bob avatar
    87 posts
    Member since:
    Jan 2008

    Posted 04 Apr 2008 Link to this post

    Piyush,

    I converted your code to vb.net as follows:

    Dim

    eitem As GridEditableItem = TryCast(e.Item, GridEditableItem)

    Dim newValues As New Hashtable()

    eitem.OwnerTableView.ExtractValuesFromItem(newValues, eitem)

    Dim id As Integer = Convert.ToInt32(newValues("PolicyId"))


    But id = 0 when I run this.  What am I doing wrong?

    Thanks,
    Bob
  5. Ves
    Admin
    Ves avatar
    2879 posts

    Posted 07 Apr 2008 Link to this post

    Hello Bob,

    Did you add DataKeyNames="PolicyId"  in the markup for the corresponding GridTableView? In code-behind it would look like this: RadGrid1.MasterTableView.DataKeyNames = new String() {"PolicyId"}

    Best regards,
    Ves
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  6. Bob
    Bob avatar
    87 posts
    Member since:
    Jan 2008

    Posted 07 Apr 2008 Link to this post

    Sorry guys, this was working all along.  I found out my client has a row with PolicyID = 0 in their database.  It just happened this was the row I was testing with.  I kept seeing the value = 0 and it threw me off.  So thanks for everyone's help.

    Bob
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017