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

[Solved] Automatic delete

4 Answers 208 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Marta
Top achievements
Rank 1
Marta asked on 17 Jun 2009, 01:34 PM
Hi,

I am trying to create a button where I can delete something from a table in my database.
I need to know the contentID of the item that was clicked so that I can use it as a parameter (@idconteudo) in my delete statement.
The column in question in called "Remover".

Here is my grid:

            <telerik:RadGrid ID="MeusFavoritos" runat="server" AllowPaging="True" AllowSorting="True" DataSourceID="GET_MEUS_FAVORITOS" GridLines="None" AutoGenerateColumns="False" PageSize="5"  ClientSettings-EnableRowHoverStyle="True" PagerStyle-Mode="NumericPages" PagerStyle-ShowPagerText="false" >
                <MasterTableView CellSpacing="-1" DataSourceID="GET_MEUS_FAVORITOS">
                    <Columns>
                        <telerik:GridHyperLinkColumn DataNavigateUrlFormatString="/lms_bd/FichaConteudo.aspx?conteudo={0}" DataTextField="Titulo" Target="_self" DataNavigateUrlFields="IDConteudo" UniqueName="Titulo" HeaderText="T&#237;tulo" SortExpression="Titulo" />
                        <telerik:GridHyperLinkColumn DataNavigateUrlFormatString="/lms_bd/conteudosTema.aspx?tema={0}" DataTextField="Tema" Target="_self" DataNavigateUrlFields="IDTema" UniqueName="Tema" HeaderText="Tema" SortExpression="Tema" />
                        <telerik:GridButtonColumn ConfirmText="Tem a certeza que quer remover este conteúdo dos seus favoritos?" ConfirmDialogType="RadWindow"
                        ConfirmTitle="Remover" ButtonType="ImageButton" CommandName="Delete" Text="Remover"
                        UniqueName="RemoverFav" ImageUrl="~/imagens/bt_apagar.gif" HeaderText="Remover" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center"  />
                    </Columns>
                </MasterTableView>
                <PagerStyle Mode="NumericPages" ShowPagerText="False" />
                <ClientSettings EnableRowHoverStyle="True" />
            </telerik:RadGrid>

My radgrid is populated by this datasource, and the problem I am having is with the delete part. I don't understand how to use the id of the content clicked for my where clause in the delete. The datasource is:

<asp:SqlDataSource ID="GET_MEUS_FAVORITOS" runat="server" ConnectionString="<%$ ConnectionStrings:lms_bibliotecaConnectionString1 %>"
                      SelectCommand="SELECT * FROM ([NL_LMS_BIB_conteudos] INNER JOIN NL_LMS_BIB_temas ON NL_LMS_BIB_conteudos.IDTema = NL_LMS_BIB_temas.IDTema)
                      INNER JOIN NL_LMS_BIB_favoritos on NL_LMS_BIB_conteudos.IDConteudo = NL_LMS_BIB_favoritos.IDConteudo
                      WHERE NL_LMS_BIB_favoritos.IDUser = @UserID" DeleteCommand="DELETE FROM [NL_LMS_BIB_favoritos] WHERE IDUser = @UserID AND IDConteudo = @idconteudo" >
    <SelectParameters>
        <asp:SessionParameter Name="UserID" SessionField="UserID" />
    </SelectParameters>
    <DeleteParameters>
        <asp:SessionParameter Name="UserID" SessionField="UserID" />
        <asp:Parameter Name="idconteudo" />
    </DeleteParameters>

</asp:SqlDataSource>

Can anyone please help?
Thank you.

4 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 17 Jun 2009, 01:52 PM
Hello Marta,

Telerik RadGrid provides rich server API for inserting new data, updating existing data and deleting data directly from the specified data source (AccessDataSource, SqlDataSource or ObjectDataSource). Keep in mind that you will have to configure the respective data source control (including update/insert/delete parameters to its definition) to trigger the automatic operations.

Please find more information in the following articles:
Automatic Operations - Demo
Automatic operations with SqlDataSource control

Kind regards,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Marta
Top achievements
Rank 1
answered on 17 Jun 2009, 01:56 PM
I have already read that in the grid demo page so that definitely does not help. I tried the example there and couldn't make it work, that is why I posted in this forum. Does anyone else have any suggestions that could help me?
0
Marta
Top achievements
Rank 1
answered on 17 Jun 2009, 02:39 PM
I fugured it out: I was missing  DataKeyNames="IDFavorito"  in my MasterTableView.

Thanks.
0
Pavlina
Telerik team
answered on 17 Jun 2009, 03:22 PM
Hello Marta,

I am happy to hear you have found a solution for your case.
Do not hesitate to write if any issues arise.

Greetings,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Marta
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Marta
Top achievements
Rank 1
Share this question
or