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

Export to Excel and Command Item help

3 Answers 253 Views
Grid
This is a migrated thread and some comments may be shown as answers.
towpse
Top achievements
Rank 2
towpse asked on 06 Apr 2010, 04:47 PM
I'm using Version=2009.3.1314.35 because the latest version seems to mess up my grid skins which I don't feel like dealing with right now.

Anyway in this version, is there an easy way to show an excel icon like in the latest? Something like showExcelIcon = true?

Also, if I don't supply a command item template, a default one renders with input elements of type submit with <a> tags.
Is there an example of how I can do this manually in the command item template?
If I just put an input element in the command item template and set runat to server, it doesn't get acknowledged by the Command Item clicked event like link buttons do. 
How do I successfully implement my own <a> tag for an input element in the command item template?

I need something like the following but i'm confused by the autogenerated $ctl00$ctl02$ctl00$ text
<a href="javascript:__doPostBack('InactiveUnitGrid$ctl00$ctl02$ctl00$RebindGridButton','')" id="InactiveUnitGrid_ctl00_ctl02_ctl00_RebindGridButton">Refresh</a>

What is this RebindGridButton that gets referenced in the doPostBack method?
Should I be able to just reference the RebindGridButton without the InactiveUnitGrid_ctl00_ctl02_ctl00_ prefix? 

3 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 09 Apr 2010, 07:20 AM
Hello towps,

To have buttons in the CommandItemTemplate  render like the predefined buttons, use the following markup:

<CommandItemTemplate>
    <table class="rgCommandTable" style="width:100%">
        <tr>
            <td>
                <asp:LinkButton ID="LinkButton1" runat="server"
                    CommandName="CustomCommand" CommandArgument="Custom"
                    Text="My Custom Button">
                </asp:LinkButton>
            </td>
        </tr>
    </table>
</CommandItemTemplate>

Setting CommandName to your link buttons is enough for the button to bubble the initiated command to RadGrid. You can thus handle the command using RadGrid's ItemCommand event:

protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
{
    if (e.CommandName == "CustomCommand")
    {
        //handle command here
    }
}
 

You can also programmatically insert link buttons in the original command item, much like the predefined command item buttons. You can use RadGrid's ItemCreated event for this purpose:

protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridCommandItem)
    {
        Table commandTable = e.Item.Cells[0].Controls[0] as Table;
        commandTable.Rows[0].Cells[0].Controls.Add(new LiteralControl("   "));
        commandTable.Rows[0].Cells[0].Controls.Add(new LinkButton
            {
                ID = "LinkButton1",
                CommandName = "CustomCommand",
                CommandArgument = "Custom",
                Text = "My Custom Command"
            });
    }
}


All the best,
Veli
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Matt
Top achievements
Rank 1
answered on 05 Jan 2011, 07:04 PM
Veli,

Per your suggestion I programmatically insert new link buttons in the original command item using RadGrid's ItemCreated event. However, the new items appear on the left side of the Command Item bar, while the default items (e.g. Refresh and ExportToExcel) appear on the right side. Even with the following code, the new items appear in the middle of the Command Item bar, not on the right side.

commandTable.Rows[0].Cells[0].HorizontalAlign =

 

HorizontalAlign.Right;

 

How can the new items appear on the right side of the Command Item bar?

Thanks,

Matt
0
Matt
Top achievements
Rank 1
answered on 05 Jan 2011, 07:09 PM
Veli,

I figured it out. I Add the items into cell 1 instead of 0. The items now appear on the right side of the Command Item bar.

        commandTable.Rows[0].Cells[1].Controls.Add(new LiteralControl("   "));
Tags
Grid
Asked by
towpse
Top achievements
Rank 2
Answers by
Veli
Telerik team
Matt
Top achievements
Rank 1
Share this question
or