Custom Delete Logic

5 posts, 1 answers
  1. Frank
    Frank avatar
    86 posts
    Member since:
    Mar 2012

    Posted 29 Mar 2012 Link to this post

    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.
  2. Nick
    Admin
    Nick avatar
    593 posts

    Posted 30 Mar 2012 Link to this post

    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 >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. Eric Klein
    Eric Klein avatar
    183 posts
    Member since:
    Aug 2009

    Posted 30 Mar 2012 Link to this post

    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
  5. Answer
    Eric Klein
    Eric Klein avatar
    183 posts
    Member since:
    Aug 2009

    Posted 30 Mar 2012 Link to this post

    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);
                    
                }
            }
  6. Nick
    Admin
    Nick avatar
    593 posts

    Posted 03 Apr 2012 Link to this post

    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 >>
Back to Top
UI for WPF is Visual Studio 2017 Ready