This is a migrated thread and some comments may be shown as answers.

GridButtonColumn Delete button

4 Answers 179 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bob
Top achievements
Rank 1
Bob asked on 04 Apr 2008, 07:20 PM
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

4 Answers, 1 is accepted

Sort by
0
Piyush Bhatt
Top achievements
Rank 2
answered on 04 Apr 2008, 07:30 PM
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"]);
0
Bob
Top achievements
Rank 1
answered on 04 Apr 2008, 07:49 PM
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
0
Ves
Telerik team
answered on 07 Apr 2008, 05:57 AM
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
0
Bob
Top achievements
Rank 1
answered on 07 Apr 2008, 01:11 PM
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
Tags
Grid
Asked by
Bob
Top achievements
Rank 1
Answers by
Piyush Bhatt
Top achievements
Rank 2
Bob
Top achievements
Rank 1
Ves
Telerik team
Share this question
or