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

[Solved] radgrid <telerik:GridButtonColumn

3 Answers 437 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tony Abou-Akl
Top achievements
Rank 1
Tony Abou-Akl asked on 04 Aug 2009, 07:29 PM
Hi there
i have a radgrid with Gridbuttoncolumn, i would like to execute a javascript code to check if i can delete this record. Is there a way to call a javascrip funtion first then execute the Delete comand 
 

<

 

telerik:GridButtonColumn ConfirmText="Delete this?" ConfirmDialogType="Classic" ConfirmTitle="Delete" ButtonType="ImageButton"

 

 

CommandName="Delete" Text="Delete" UniqueName="DeleteColumn"

Thanks
Tony

 

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 05 Aug 2009, 06:34 AM
Hi Tony,

I hope you need to execute a client side code before showing the confirm and then fire the server side DeleteCommand. If so here is a sample code which I tried on my end. You may alter the logic accordingly.

ASPX:
 
<telerik:GridButtonColumn  ButtonType="ImageButton" CommandName="Delete" Text="Delete" UniqueName="DeleteColumn" ImageUrl="~/Images/Delete.gif"
 </telerik:GridButtonColumn> 

CS:
 
 protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem item = (GridDataItem)e.Item; 
            ImageButton deleteBtn = (ImageButton)item["DeleteColumn"].Controls[0]; 
            deleteBtn.Attributes.Add("OnClick","return ConfirmDelete('"+ item.ItemIndex +"');"); 
        }  
    } 

JS:
 
<script type="text/javascript"
 
function ConfirmDelete(rowindex) 
  if(rowindex==1) 
   if(confirm("Delete this?")) 
    return true
    else 
    return false
   
    
  
</script> 
 


Thanks
Princy
0
Scott Cullen
Top achievements
Rank 1
answered on 05 Oct 2009, 04:34 PM
Hi, I have a similar question, but in my case I also have a DetailsTable in my RadGrid. Using the above example I receive an error on the following line when the ItemDataBound event is called for my Details table because I do not have a DeleteColumn in the Details table.

ImageButton deleteBtn = (ImageButton)item["DeleteColumn"].Controls[0];

My question is, how do I determine if the current table is the Details table so that I can skip calling the above line of code?

Thanks, -Scott
0
Princy
Top achievements
Rank 2
answered on 06 Oct 2009, 04:25 AM
Hi Scott,

You can diferentiate between the detailtable and the mastertable using the Name properties of the ownertableviews as shown below:
aspx:
<telerik:RadGrid ID="RadGrid1" DataSourceID="SqlDataSource1" runat="server" OnItemDataBound="RadGrid1_ItemDataBound"
     <MasterTableView Name="Master" DataSourceID="SqlDataSource1"
           <DetailTables> 
                 <telerik:GridTableView Name="Detail" DataSourceID="SqlDataSource1" runat="server">                           

c#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)  
    {  
        if (e.Item is GridDataItem && e.Item.OwnerTableView.Name=="Master")  
        {  
            GridDataItem item = (GridDataItem)e.Item;  
            ImageButton deleteBtn = (ImageButton)item["DeleteColumn"].Controls[0];  
            deleteBtn.Attributes.Add("OnClick","return ConfirmDelete('"+ item.ItemIndex +"');");  
        }   
    }  

Thanks
Princy.
Tags
Grid
Asked by
Tony Abou-Akl
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Scott Cullen
Top achievements
Rank 1
Share this question
or