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

Selecting row on Delete click

2 Answers 101 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Eliyahu Goldin
Top achievements
Rank 1
Eliyahu Goldin asked on 28 Aug 2008, 09:41 AM
Is there a way to make a row selected on clicking Delete button?

In my grid, I have a GridButtonColumn with a Delete button. I use a classic confirmation dialog. When I click the Delete button on a grid row, I would like the row to become Selected before the confirmation dialog is produced. With the row selected, the dialog could contain just a generic text "Woud you like to delete the selected row?". As it is now, it is not clear from the dialog what row is about to be deleted.

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 28 Aug 2008, 10:19 AM
Hi,

Try accessing the linkButton of the GridButtonColumn in the code behind and add a client event for the LinkButton and select the clicked item on the client side as shown below.

ASPX:
  <telerik:GridButtonColumn UniqueName="DeleteCol" Text="Delete"  CommandName="DeleteItem" ></telerik:GridButtonColumn> 
              

CS:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem item = (GridDataItem)e.Item; 
            int RowIndex = item.ItemIndex; 
            LinkButton lnkbtn = (LinkButton)item["DeleteCol"].Controls[0]; 
            lnkbtn.Attributes.Add("OnClick", "return Select('" + RowIndex + "');"); 
        } 
                
    } 


JS:
 <script type="text/javascript" language="javascript" > 
         
        function Select(RowIndex) 
        { 
         var RadGrid1 = $find("<%= RadGrid1.ClientID %>"); 
         RadGrid1.get_masterTableView().get_dataItems()[RowIndex].set_selected("true"); 
         alert('Do you want to delete the Selected Item?') 
        } 
  </script > 


Cheers
Shinu.
0
Eliyahu Goldin
Top achievements
Rank 1
answered on 28 Aug 2008, 04:38 PM
In my case this looks too complicated. I inherit my grid from RadGrid and already have some logic involving ConfirmText property of GridButtonColumn. There are too many ends to tie together. I was hoping for something simpler.

Thank you anyway!
Tags
Grid
Asked by
Eliyahu Goldin
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Eliyahu Goldin
Top achievements
Rank 1
Share this question
or