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

[Solved] same GridButtonColumn for delete and update

2 Answers 120 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Marta
Top achievements
Rank 1
Marta asked on 02 Jul 2009, 10:51 AM

Hi,

I have a GridButtonColumn in my RadGrid which is a delete button for a tag and executes the deletecommand defined in my datasource. This delete actually deletes the pair "contentID" and "tagID" from my table tagsContents. However, as well as the delete of this pair from my table tagsContents, I also want to execute an update of my table tags where I decrease the count column of that tag by 1. This means that as I delete the pair tag - content, I also must decrease the count in the tags table. How can I execute this update command when I click the delete button? Can I associate both commands to the action of clicking the button? Here is my code:

This is the GridButtonColumn:

<telerik:GridButtonColumn ConfirmText="Tem a certeza de que pretende apagar esta tag deste conteúdo?" ConfirmDialogType="RadWindow" ConfirmTitle="Apagar" ButtonType="ImageButton" ButtonCssClass="pointer" CommandName="Delete" Text="Apagar" ItemStyle-Width="10%" UniqueName="ApagarTag" ImageUrl="~/imagens/bt_scorm_falhou.gif" ItemStyle-HorizontalAlign="Center" />

This is the datasource:

<asp:SqlDataSource ID="GET_TAGS_CONT" runat="server" ConnectionString="<%$ ConnectionStrings:lms_bibliotecaConnectionString1 %>"
                      SelectCommand="SELECT * FROM NL_LMS_BIB_tags INNER JOIN NL_LMS_BIB_tagsConteudos ON NL_LMS_BIB_tags.IDTag=NL_LMS_BIB_tagsConteudos.IDTag AND NL_LMS_BIB_tagsConteudos.IDConteudo = @idconteudo"
                      DeleteCommand="DELETE FROM [NL_LMS_BIB_tagsConteudos] WHERE IDTag = @IDTag AND IDConteudo=@idconteudo" >
    <SelectParameters>
        <asp:SessionParameter Name="idconteudo" SessionField="idconteudo" />
    </SelectParameters>
    <DeleteParameters>
        <asp:SessionParameter Name="idconteudo" SessionField="idconteudo" />
        <asp:Parameter Name="IDTag" />
    </DeleteParameters>
</asp:SqlDataSource>

Thanks!
Marta

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 02 Jul 2009, 11:56 AM
Hi Marta,

One suggestion would be adding another SqlDataSource for updating the tags table and set the UpdateCommand as below inside DeleteCommand event of radgrid.

C#:
 
protected void RadGrid1_DeleteCommand(object source, GridCommandEventArgs e) 
     . . . 
    SqlDataSource2.UpdateCommand = String.Format("Update tags set count=Count-1 where TagID='{0}'", (e.Item as GridDataItem)["TagID"].Text.ToString()); 
    SqlDataSource1.Update(); 

-Shinu
0
Marta
Top achievements
Rank 1
answered on 02 Jul 2009, 03:02 PM
Thanks Shinu, I'm almost there but having a little problem:

with the line:

UPDATE_TAGS.UpdateCommand = String.Format("Update NL_LMS_BIB_tags set Count = Count - 1 where IDTag = '{0}'", (e.Item as GridDataItem)["IDTag"].Text.ToString());

because my IDTag field is a Guid, I can't seem to get it to compare and work...

 

Tags
Grid
Asked by
Marta
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Marta
Top achievements
Rank 1
Share this question
or