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

CommandItemSettings Question

1 Answer 145 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 23 Jun 2011, 04:50 PM
I'm creating my grid programmatically and wondering how I can add a custom button in addition to the export to Excel and CSV buttons already there. Here's a snippet of my code:

rgReport.MasterTableView.CommandItemSettings.ShowExportToCsvButton = (bool)resultsDT.Rows[0]["ShowExportToCsvButton"];
rgReport.MasterTableView.CommandItemSettings.ShowExportToExcelButton = (bool)resultsDT.Rows[0]["ShowExportToExcelButton"];
rgReport.MasterTableView.CommandItemSettings.ShowAddNewRecordButton = false;

Again, I want to add a custom button, but not sure how to go about doing that programmatically. I know I can use the CommandItemTemplate, but I'm not sure if I have to recreate the export functionality or if I can simply add another button to the already existing CommandItemSettings.

Any help would be appreciated.

Mark

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 28 Jun 2011, 04:47 PM
Hello Mark,

Both ways will be easy to implement:

1) CommandItemTemplate
<CommandItemTemplate>
    <table class="rcCommandTable" width="100%">
        <td>
            <asp:Button ID="Button1" runat="server" Text=" " CssClass="rgExpCSV" CommandName="ExportToCSV" />
            <asp:Button ID="Button2" runat="server" Text=" " CssClass="rgExpPDF" CommandName="ExportToPdf" />
        </td>
        <td style="float: right">
            <asp:Button ID="Button3" runat="server" Text=" " CssClass="rgAdd" CommandName="InitInsert" />
        </td>
    </table>
</CommandItemTemplate>

2) Programmatic button
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridCommandItem)
    {
        var parentCell = e.Item.FindControl("InitInsertButton").Parent;
        LinkButton btn = new LinkButton();
        btn.ID = "NewButton1";
        btn.Text = "PDF EXPORT";
        btn.CommandName = "ExportToPdf";
        parentCell.Controls.Add(btn);
    }
}

Kind regards,
Daniel
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
Mark
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or