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

How do i append button to GridGroupHeaderItem

5 Answers 28 Views
Grid
This is a migrated thread and some comments may be shown as answers.
moegal
Top achievements
Rank 1
moegal asked on 05 Mar 2015, 12:45 PM
How do I append a PushButton to GridGroupHeaderItem. I see that I can add a button but I would like to keep the current text and also get a value for the button from the command arg if possible.

I can do the following in ItemCreated and ItemDatabound but it does not work as expected. This replaced the header text all together.

if (e.Item is GridGroupHeaderItem)
            {
                GridGroupHeaderItem header = (GridGroupHeaderItem)e.Item;
                Button lnkbtn = new Button();
                lnkbtn.ID = "Button1";
                lnkbtn.Text = "Click";
                header.DataCell.Controls.Add(lnkbtn);
            }

I have tried with header.Cells[0].Controls.Add(lnkbtn); and it kinda works but pushes the button onto a new line. I would like the button to the right of the group header text and if possible, all the way to the right side.

Thanks, Marty

5 Answers, 1 is accepted

Sort by
0
Angel Petrov
Telerik team
answered on 10 Mar 2015, 07:26 AM
Hi Marty,

In order to achieve the desired goal I recommend replacing the currently used column with a GridTemplateColumn and defining a HeaderTemplate according to your needs(please refer to the following example).

ASPX:
<telerik:GridTemplateColumn UniqueName="CustomerID" DataField="CustomerID">
                       <HeaderTemplate>
                           CustomerID text
                           <asp:Button Text="Click" ID="button1" runat="server" />
                       </HeaderTemplate>
                       <ItemTemplate>
                           <%#Eval("CustomerID")%>
                       </ItemTemplate>
                   </telerik:GridTemplateColumn>
By following the above approach you should be able to both visualize the text and display a button in the header cell.

Regards,
Angel Petrov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
moegal
Top achievements
Rank 1
answered on 10 Mar 2015, 12:41 PM
Angel,  thanks but I am looking for the grouping header not the column header.

any suggestions on: GridGroupHeaderItem

Marty
0
Angel Petrov
Telerik team
answered on 13 Mar 2015, 10:59 AM
Hello Marty,

In order to achieve the desired goal for the group headers you can use a GroupHeaderTemplate. Information about it can be found in this help article.

Regards,
Angel Petrov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
moegal
Top achievements
Rank 1
answered on 13 Mar 2015, 12:31 PM
Thanks.  we are getting closer. I used sample code right from your link.

I have a field named ProductName but the following does not seem to work in <GroupHeaderTemplate>

<asp:Label runat="server" ID="Label3" Text='<%# "Product name: "+Eval("ProductName") %>'
Visible='<%# ((((GridGroupHeaderItem)Container).AggregatesValues["ProductName"]) != null)%>'></asp:Label>

The label shows/hides like it should but only reads:  "Product Name: "

It should read: "Product Name: Product 1" etc.

The Eval part is not "Eval'ing".

Any ideas?
Marty


0
moegal
Top achievements
Rank 1
answered on 13 Mar 2015, 04:05 PM
I figured it out. 

I added FieldAlias="Product"  to the GridGroupByField and changed Eval("ProductName") to Eval("Product") and it works.

Thanks,

Marty
Tags
Grid
Asked by
moegal
Top achievements
Rank 1
Answers by
Angel Petrov
Telerik team
moegal
Top achievements
Rank 1
Share this question
or