8 Answers, 1 is accepted
0

Princy
Top achievements
Rank 2
answered on 28 Jul 2008, 10:50 AM
Hi,
Try the following code snippet to achieve the desired scenario.
CS:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) |
{ |
if (e.Item is GridGroupHeaderItem) |
{ |
GridGroupHeaderItem groupHeader = (GridGroupHeaderItem)e.Item; |
Button exportBtn = new Button(); |
exportBtn.ID = "exportBtn1"; |
exportBtn.Text = "Export to Word"; |
exportBtn.Click += new EventHandler(exportBtn_Click); |
groupHeader.DataCell.Controls.Add(exportBtn); |
} |
} |
protected void exportBtn_Click(object sender, EventArgs e) |
{ |
RadGrid1.ExportSettings.OpenInNewWindow = true; |
RadGrid1.MasterTableView.ExportToWord(); |
} |
Hope this helps..
Princy.
0

Twalker
Top achievements
Rank 1
answered on 20 Aug 2008, 02:55 PM
I could not get the button to display group header section of my grid. Are there any settings that need to be enabled on the RadGrid?
0

Shinu
Top achievements
Rank 2
answered on 21 Aug 2008, 05:18 AM
Hi Twalker,
Can you try adding the button in both ItemCreated and ItemDataBound event and see if it is working.
CS:
Thanks
Shinu.
Can you try adding the button in both ItemCreated and ItemDataBound event and see if it is working.
CS:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) |
{ |
if (e.Item is GridGroupHeaderItem) |
{ |
GridGroupHeaderItem header = (GridGroupHeaderItem)e.Item; |
Button btn = new Button(); |
btn.ID = "Button1"; |
btn.Text = "Export"; |
header.DataCell.Controls.Add(btn); |
} |
} |
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) |
{ |
if (e.Item is GridGroupHeaderItem) |
{ |
GridGroupHeaderItem header = (GridGroupHeaderItem)e.Item; |
Button btn = new Button(); |
btn.ID = "Button1"; |
btn.Text = "Export"; |
btn.Click += new EventHandler(btn_Click); |
header.DataCell.Controls.Add(btn); |
} |
} |
void btn_Click(object sender, EventArgs e) |
{ |
RadGrid1.ExportSettings.OpenInNewWindow = true; |
RadGrid1.MasterTableView.ExportToWord(); |
} |
Thanks
Shinu.
0

Twalker
Top achievements
Rank 1
answered on 21 Aug 2008, 01:50 PM
Hi Shinu,
No luck with adding the button to the group header. I did try you last suggestion of adding the code to both the RadGrid's ItemCreated and ItemBound events.
Here is my setup of my RadGrid. I have added a export button outside the grid but that has no sex appeal :)
No luck with adding the button to the group header. I did try you last suggestion of adding the code to both the RadGrid's ItemCreated and ItemBound events.
Here is my setup of my RadGrid. I have added a export button outside the grid but that has no sex appeal :)
<telerik:RadGrid ID="RadGridProductSales" runat="server" AllowPaging="True" |
Skin="Hay" GridLines="None" AllowSorting="True" |
AutoGenerateColumns="False" ShowFooter="True" |
DataSourceID="SqlDataSource1" PageSize="25" |
onitemcreated="RadGridProductSales_ItemCreated" |
onitemdatabound="RadGridProductSales_ItemDataBound" > |
<ExportSettings ExportOnlyData="True" FileName="ProductCommercialSalesbyVendor" |
IgnorePaging="True" OpenInNewWindow="True"> |
<Excel Format="ExcelML" /> |
</ExportSettings> |
<MasterTableView DataSourceID="SqlDataSource1" PageSize="10" CommandItemDisplay="Top" |
GroupLoadMode="Client"> |
0
Hi Twalker,
I'd suggest you try adding controls in the Grid cells in Grid_PreRender event. Let us know whether this helps or if you need further assistance.
Best wishes,
Konstantin Petkov
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
I'd suggest you try adding controls in the Grid cells in Grid_PreRender event. Let us know whether this helps or if you need further assistance.
Best wishes,
Konstantin Petkov
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0

Twalker
Top achievements
Rank 1
answered on 21 Aug 2008, 02:20 PM
Hi Konstantin,
Could you direct me to a article I can read up on how to acquire the reference to the Radgrid elements to be able to add the button to the cell area.
I did see an example on the telerik where the demo used a custom commandItemTemplate within the RadGrid. I add my own button into this area. How would intercept the button's click event?
Thanks.
Could you direct me to a article I can read up on how to acquire the reference to the Radgrid elements to be able to add the button to the cell area.
I did see an example on the telerik where the demo used a custom commandItemTemplate within the RadGrid. I add my own button into this area. How would intercept the button's click event?
<MasterTableView DataSourceID="SqlDataSource1" PageSize="10" CommandItemDisplay="Top"> |
<CommandItemTemplate> |
<div style="padding:10px 0px;"> |
Custom command item template |
<asp:Button ID="Button1" runat="server" Text="Button" /> |
</CommandItemTemplate> |
Thanks.
0

Shinu
Top achievements
Rank 2
answered on 22 Aug 2008, 05:33 AM
Hi Twalker,
Try the following code snippet to export the Grid on clicking the Export button in the CommandItemTemplate.
ASPX:
CS:
Thanks
Shinu.
Try the following code snippet to export the Grid on clicking the Export button in the CommandItemTemplate.
ASPX:
<CommandItemTemplate> |
<asp:Button ID="Button2" runat="server" Text="Export" OnClick="Button2_Click" /> |
</CommandItemTemplate> |
CS:
protected void Button2_Click(object sender, EventArgs e) |
{ |
RadGrid1.ExportSettings.OpenInNewWindow = true; |
RadGrid1.MasterTableView.ExportToExcel(); |
} |
Thanks
Shinu.
0

Twalker
Top achievements
Rank 1
answered on 22 Aug 2008, 01:38 PM
Hi Shinu,
Thank you, your code worked like a charm. Now my little app has sex appeal! :)
Thank you, your code worked like a charm. Now my little app has sex appeal! :)