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

[Solved] Add number of records selected for deletion to the confirm dialogue box

2 Answers 165 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Cathy
Top achievements
Rank 1
Cathy asked on 20 Jul 2009, 06:17 PM

I need to add the number of records selected for deletion to the confirm dialogue box.

I have a RadGrid with a programmatically added GridClientSelectColumn (for the checkboxes for each row in the grid) and GridCommandItem that is a linkbutton with text = "Delete Selected". What I like to be able to do is have a confirmation dialog box appear with the number of records the client as has selected to delete.

protected

 

void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)

 

{

    if

 

(e.Item is GridCommandItem)

 

    {

 

        LinkButton Delete = e.Item.FindControl("btnDeleteSelected") as LinkButton;

 

 

        string js = null;

 

        js =

"javascript:return confirm('Do you want to DELETE ";

 

        js = js + RadGrid1.SelectedIndexes.Count +

" record(s)?')";

 

        Delete.Attributes[

"onclick"] = js;

 

    }

}

I have tried the above in the code behind but the RadGrid1.SelectedIndexes.Count is always 0.

I realize this maybe because the ItemCreated event is triggered before the SelectedIndexChanged event.

On server selection from Select/Deselect GridButtonColumn/Auto Postback on row click:

 

For each Item in grid:

 

    ItemCreated 

 

Page.Load

 

ItemCommand

 

SelectedIndexChanged

 

Other postback events

 

Page.PreRender

 

So, is there anyway I can get the count of the selected records and pass it to the confirm javascript when I click on my Delet Selected link button??

Thanks in advance for your advice,

cathy

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 21 Jul 2009, 07:11 AM
Hi Cathy,

I tried another approach by adding onClientClick event from ASPX instead of adding from code behind. Give a try with the following code and see whether it is useful for you.

ASPX:
 
  . . . 
<CommandItemTemplate> 
    <asp:LinkButton ID="LinkButton1" runat="server"  OnClientClick="return ConfirmIt();" OnClick="LinkButton1_Click">Delete Selected</asp:LinkButton> 
</CommandItemTemplate> 
  . . . 

JavaScript:
 
<script type="text/javascript"
function ConfirmIt() 
     var grid = $find("<%=RadGrid1.ClientID %>");   
     var MasterTable = grid.get_masterTableView(); 
     var selected = MasterTable.get_selectedItems().length; 
     if(selected != 0) 
     { 
        var result = confirm('Do you want to DELETE '+ selected +' record(s)?'); 
        return(result); 
     } 
     else 
     { 
        alert('No rows selected'); 
        return(false);    
     } 
</script> 

-Shinu.
0
Cathy
Top achievements
Rank 1
answered on 21 Jul 2009, 06:30 PM
Hi Shinu,

That worked beautifully, thank you very much!

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