Export to Excel Button Text

5 posts, 0 answers
  1. Mark
    Mark avatar
    127 posts
    Member since:
    May 2013

    Posted 22 Oct 2013 Link to this post

    Hi All!

    Is there anyway to include some text to the left of the Export to Excel button icon in the top right of a RadGrid?  I do know that you can change the mouse-over text.

    Thanks,
    Mark
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 23 Oct 2013 Link to this post

    Hi Mark,

    One suggestion is to add a Literal Control next to the export button as shown below.

    C#:
    protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
    {
        if (e.Item is GridCommandItem)
        {
            GridCommandItem cmd = (GridCommandItem)e.Item;
            Button btn = (Button)cmd.FindControl("ExportToExcelButton");
            LiteralControl lbl = new LiteralControl();
            lbl.Text = "ExportToExcel";
            lbl.ID = "lblExport";
            btn.Parent.Controls.AddAt(4,lbl);           
        }
    }

    Thanks,
    Princy.
  3. Mark
    Mark avatar
    127 posts
    Member since:
    May 2013

    Posted 23 Oct 2013 Link to this post

    Hi Princy,

    The code worked perfectly!  Thanks!

    Is there a way to make the lbl an extension of the Excel Button, so you can click on it as well to export? 

    I could certainly switch lbl to a link button and make my own click event handler for the export.

    Thanks,
    Mark
  4. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 24 Oct 2013 Link to this post

    Hi Mark,

    To obtain the Export on click of the text,you have to use LinkButton and instead of using the event handler you can set CommandName. Please move the code to ItemCreated event.Try the following code snippet.

    C#:
    protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridCommandItem)
        {
            GridCommandItem cmd = (GridCommandItem)e.Item;
            Button btn = (Button)cmd.FindControl("ExportToExcelButton");
            LinkButton lnk = new LinkButton();
            lnk.Text = "ExportToExcel";
            lnk.ID = "lnkExport";
            lnk.CommandName = "ExportToExcel";
            btn.Parent.Controls.AddAt(4, lnk);
        }
    }

    Thanks,
    Princy
  5. Mark
    Mark avatar
    127 posts
    Member since:
    May 2013

    Posted 24 Oct 2013 Link to this post

    Worked great!  Thanks a bunch!  :-)
Back to Top