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

Custom Delete Logic

4 Answers 61 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Frank
Top achievements
Rank 1
Frank asked on 29 Mar 2012, 09:49 PM
I have a GridView which the user can Delete rows from.  This works on the screen but I need it to fire a stored procedure to delete records form the data base.  I and using the Deleting Event but I am unsure how to get the data from the items being deleted.  I want to retrive a cell value to pass as a paramater to a stored procedure to delete records from the database.

4 Answers, 1 is accepted

Sort by
0
Nick
Telerik team
answered on 30 Mar 2012, 03:11 PM
Hello Frank,

You can access all the items that are being deleted in the e.Items property, and get all the information you need from there. 

I want to retrive a cell value to pass as a paramater to a stored procedure to delete records from the database. 
If you need the value from a cell that is not bound to any property in the row's object, you can use the GridView's ItemContainerGenerator to get the row in which the item is located. Mind however that when the RowVirtualization is turned on and the item that you are deleting is not in the ViewPort, this won't work. The reason is when an item is not visible there is no row realized for it in order to boost the performance of the GridView.

Hope this helps! 

Kind regards,
Nik
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Eric Klein
Top achievements
Rank 1
answered on 30 Mar 2012, 03:19 PM
Ok I see that but how do I get the value of the cell.

<telerik:RadGridView HorizontalAlignment="Left" Margin="153,20,0,0" Name="FilesLoadedGrid" VerticalAlignment="Top" Height="233" Width="439" AutoGenerateColumns="False"
                     CanUserFreezeColumns="False" CanUserReorderColumns="False" CanUserResizeColumns="False"  RowIndicatorVisibility="Collapsed" ShowGroupPanel="False"
                      AlternationCount="2"  AlternateRowBackground="Cornsilk"  Deleting="FileDeleted" >
    <telerik:RadGridView.Columns>
        <telerik:GridViewColumn >
            <telerik:GridViewColumn.CellTemplate>
                <DataTemplate>
                    <telerik:RadButton Content="Delete" Command="telerikGrid:RadGridViewCommands.Delete" CommandParameter="{Binding SelectedItem}" />
                </DataTemplate>
            </telerik:GridViewColumn.CellTemplate>
        </telerik:GridViewColumn>
        <telerik:GridViewDataColumn Header="Loaded File" Name="FileLoaded" DataMemberBinding="{Binding LoadedFile}"  Width="*" >
        </telerik:GridViewDataColumn>
    </telerik:RadGridView.Columns>

The grid is loaded with a datable.

I am using the Deleting how do I get the selected row value for the FileLoaded cell
0
Accepted
Eric Klein
Top achievements
Rank 1
answered on 30 Mar 2012, 03:46 PM
Ok I have found a way to get it to work I am not sure if this is the best way to accomplish this but this is what I have found

I just need to add the delet functionality but I know I am getting the file name from th deleted record.
public void FileDeleted(object sender, GridViewDeletingEventArgs e)
        {
            foreach (object itemToDelete in e.Items)
            {
                string fileName = (((DataRowView)itemToDelete).Row.ItemArray).GetValue(0).ToString();
                MessageBox.Show(fileName);
                
            }
        }
0
Nick
Telerik team
answered on 03 Apr 2012, 08:44 AM
Hello Eric,

Glad to see you found the right way on your own. Nevertheless, if you need any further help, don't hesitate to ask! 

All the best,
Nik
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
GridView
Asked by
Frank
Top achievements
Rank 1
Answers by
Nick
Telerik team
Eric Klein
Top achievements
Rank 1
Share this question
or