I have created a RadGrid dynamically and added it to a placeholder at Page_Init event.
I'd need to add a custom button to the CommandItem and for this I've tried many scenarios and none of which has worked properly:
1) I added the custom button at RadGrid_ItemCreated event. The button appears. When it's clicked, it posts back, however, its click event handler is never raised. why? how to fix it?
My button is a normal ASP.NET button:
private Button CreateExportToPdfButton()
{
var result = new Button();
result.ID = "btnExportToPdf";
result.Click += ExportToPdfButtonClick;
result.CssClass = "rgExpPDF";
result.CommandName = "ExportToPdfCustomCommand";
result.Attributes["title"] = "Export to Pdf";
return result;
}
Also I tried managing it in the ItemCommand event when the button is clicked:
but ItemCommand event doesn't get raised either when the button is clicked.
2) I added the custom button at RadGrid_MasterTableView_Load. The button appears and when it's clicked, it posts back and click event is raised as expected which is great. As soon as sorting is enabled on the RadGrid and a column header is selected to be sorted, the sorting happens however my custom button disappears. Why? how to fix it?
3) On RadGrid_MasterTableView_Init; behaves similar to #2
4) On RadGrid_MasterTableView_PreRender; behaves similar to #1
5) On RadGrid_Init, behaves similar to #2
6) Another possible approach comes to mind is to create a new CommandItemTemplate: http://www.telerik.com/help/aspnet/grid/grdcommanditemtemplate.html
in which case, the click event and itemcommand events are raised properly.
But there is an issue with this approach that it would be more complex as I'm using the built-in Export to Word and Excel functionalities of RadGrid currently. so not sure how to add these 2 to the CommandItemTemplate this way?
I'd rather making the previous approaches working if possible.
Your help is very much appreciated on any of these approaches.
I'd need to add a custom button to the CommandItem and for this I've tried many scenarios and none of which has worked properly:
1) I added the custom button at RadGrid_ItemCreated event. The button appears. When it's clicked, it posts back, however, its click event handler is never raised. why? how to fix it?
My button is a normal ASP.NET button:
private Button CreateExportToPdfButton()
{
var result = new Button();
result.ID = "btnExportToPdf";
result.Click += ExportToPdfButtonClick;
result.CssClass = "rgExpPDF";
result.CommandName = "ExportToPdfCustomCommand";
result.Attributes["title"] = "Export to Pdf";
return result;
}
Also I tried managing it in the ItemCommand event when the button is clicked:
protected
void
RadGrid1_ItemCommand(
object
sender, GridCommandEventArgs e)
{
if
(e.CommandName ==
"ExportToPdfCustomCommand"
)
{
//my code here
}
}
but ItemCommand event doesn't get raised either when the button is clicked.
2) I added the custom button at RadGrid_MasterTableView_Load. The button appears and when it's clicked, it posts back and click event is raised as expected which is great. As soon as sorting is enabled on the RadGrid and a column header is selected to be sorted, the sorting happens however my custom button disappears. Why? how to fix it?
3) On RadGrid_MasterTableView_Init; behaves similar to #2
4) On RadGrid_MasterTableView_PreRender; behaves similar to #1
5) On RadGrid_Init, behaves similar to #2
6) Another possible approach comes to mind is to create a new CommandItemTemplate: http://www.telerik.com/help/aspnet/grid/grdcommanditemtemplate.html
in which case, the click event and itemcommand events are raised properly.
But there is an issue with this approach that it would be more complex as I'm using the built-in Export to Word and Excel functionalities of RadGrid currently. so not sure how to add these 2 to the CommandItemTemplate this way?
I'd rather making the previous approaches working if possible.
Your help is very much appreciated on any of these approaches.