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

Button in Group Header

4 Answers 208 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kyle
Top achievements
Rank 1
Kyle asked on 26 Nov 2014, 07:29 PM
Hi All,

I have an ajaxified grid for which I'm trying to add a button to a certain group header.  In this case I'm just trying to display the button where the Display Name is.

  <telerik:GridGroupByExpression><br>                                        <GroupByFields><br>                                            <telerik:GridGroupByField FieldName="DisplayName" FieldAlias="DisplayName" HeaderText="Employee"<br>                                                HeaderValueSeparator=": " Aggregate="None" /><br>                                            <telerik:GridGroupByField FieldName="UserId" FieldAlias="UserId" HeaderText="" HeaderValueSeparator=""<br>                                                Aggregate="None" /><br>                                            <telerik:GridGroupByField FieldName="CheckNumber" FieldAlias="CheckNumber" HeaderText=""<br>                                                HeaderValueSeparator="" Aggregate="None" /><br>                                            <telerik:GridGroupByField FieldName="appliedToDate" FieldAlias="appliedToDate" HeaderText=""<br>                                                HeaderValueSeparator="" Aggregate="None" /><br>                                            <telerik:GridGroupByField FieldName="PaidDate" FieldAlias="PaidDate" HeaderText=""<br>                                                HeaderValueSeparator="" Aggregate="None" /><br>                                            <telerik:GridGroupByField FieldName="LineHeaderID" FieldAlias="LineHeaderID" HeaderText=""<br>                                                HeaderValueSeparator="" Aggregate="None" /><br>                                        </GroupByFields><br>                                        <SelectFields><br>                                            <telerik:GridGroupByField FieldName="DisplayName" FieldAlias="DisplayName" HeaderText="Employee"<br>                                                HeaderValueSeparator=": " Aggregate="None" /><br>                                            <telerik:GridGroupByField FieldName="RequestedAmount" FieldAlias="RequestedAmount"<br>                                                HeaderText="<br />Requested Total" HeaderValueSeparator=": $" Aggregate="Sum" /><br>                                            <telerik:GridGroupByField FieldName="ApprovedAmount" FieldAlias="ApprovedAmount"<br>                                                HeaderText="Approved Total" HeaderValueSeparator=": $" Aggregate="Sum" /><br>                                        </SelectFields><br>                                    </telerik:GridGroupByExpression><br>                                    <telerik:GridGroupByExpression><br>                                        <GroupByFields><br>                                            <telerik:GridGroupByField FieldName="Category" FieldAlias="Category" HeaderText="Category"<br>                                                HeaderValueSeparator=": " Aggregate="None" /><br>                                        </GroupByFields><br>                                        <SelectFields><br>                                            <telerik:GridGroupByField FieldName="CategoryText" FieldAlias="CategoryText" HeaderText="Category"<br>                                                HeaderValueSeparator=": " Aggregate="None" /><br>                                            <telerik:GridGroupByField FieldName="RequestedAmount" FieldAlias="RequestedAmount"<br>                                                HeaderText="Requested Total" HeaderValueSeparator=": $" Aggregate="Sum" /><br>                                            <telerik:GridGroupByField FieldName="ApprovedAmount" FieldAlias="ApprovedAmount"<br>                                                HeaderText="Total" HeaderValueSeparator=": $" Aggregate="Sum" /><br>                                        </SelectFields><br>                                    </telerik:GridGroupByExpression><br>                                    <telerik:GridGroupByExpression><br>                                        <GroupByFields><br>                                            <telerik:GridGroupByField FieldName="order_no" FieldAlias="order_no" HeaderText="Order Number"<br>                                                HeaderValueSeparator=": " Aggregate="None" /><br>                                        </GroupByFields><br>                                        <SelectFields><br>                                            <telerik:GridGroupByField FieldName="order_no" FieldAlias="order_no" HeaderText="Order Number"<br>                                                HeaderValueSeparator=": " Aggregate="None" /><br>                                            <telerik:GridGroupByField FieldName="RequestedAmount" FieldAlias="RequestedAmount"<br>                                                HeaderText="Requested Total" HeaderValueSeparator=": $" Aggregate="Sum" /><br>                                            <telerik:GridGroupByField FieldName="ApprovedAmount" FieldAlias="ApprovedAmount"<br>                                                HeaderText="Total" HeaderValueSeparator=": $" Aggregate="Sum" /><br>                                        </SelectFields><br>                                    </telerik:GridGroupByExpression><br><br><br> <GroupHeaderTemplate><br>                                    <asp:Panel runat="server" ID="pnlEmployee" Visible='<%# ((((GridGroupHeaderItem)Container).AggregatesValues["DisplayName"]) != null)%>'<br>                                        Style="height: 20px !important"><br>                                        <asp:Label runat="server" ID="lblEmployee" Text='<%# "Employee: " +Eval("DisplayName")  %> '><br>                                        </asp:Label><br>                                    </asp:Panel><br>                                    <asp:Label runat="server" ID="lblCategory" Text='<%# "Category: "+ (((GridGroupHeaderItem)Container).AggregatesValues["CategoryText"]) %>'<br>                                        Visible='<%# ((((GridGroupHeaderItem)Container).AggregatesValues["CategoryText"]) != null)%>'<br>                                        Style="margin-right: 30px;"></asp:Label><br>                                    <asp:Label runat="server" ID="lblOrderNo" Text='<%# "Order Number: "+ (((GridGroupHeaderItem)Container).AggregatesValues["order_no"]) %>'<br>                                        Visible='<%# ((((GridGroupHeaderItem)Container).AggregatesValues["order_no"]) != null)%>'<br>                                        Style="margin-right: 30px;"></asp:Label><br>                                    <asp:Label runat="server" ID="lblRequestedTotal" Text='<%# "Requested Total: $"+ (((GridGroupHeaderItem)Container).AggregatesValues["RequestedAmount"]) %>'<br>                                        Visible='<%# ((((GridGroupHeaderItem)Container).AggregatesValues["RequestedAmount"]) != null)%>'<br>                                        Style="margin-left: 30px;"></asp:Label><br>                                    <asp:Label runat="server" ID="lblApprovedTotal" Text='<%# "Approved Total: <b>$" + (((GridGroupHeaderItem)Container).AggregatesValues["ApprovedAmount"]) + "</b></br>" %>'<br>                                        Visible='<%# ((((GridGroupHeaderItem)Container).AggregatesValues["ApprovedAmount"]) != null)%>'<br>                                        Style="margin-left: 30px;"><br>                                       <br>                                    </asp:Label><br>                                </GroupHeaderTemplate>


I have in the itemCreated added that button:
protected void rgLineItems_ItemCreated(object sender, GridItemEventArgs e)<br>   
{<br>       
        if (e.Item is GridGroupHeaderItem && e.Item.GroupIndex.Split('_').Length == 1)<br>
        {<br> 
           GridGroupHeaderItem hi = e.Item
as GridGroupHeaderItem;<br>
            DataRowView drv = ((DataRowView)e.Item.DataItem);<br>
            Button btn =
new Button();<br>
            btn.ID =
"btnUpdateHeader";<br>
            btn.Text =
string.IsNullOrWhiteSpace(drv["PaidDate"].ToString()) ? "Pay Employee" : "Update Payment";<br>
            btn.CommandArgument = drv[
"UserID"].ToString() + "/" + (string.IsNullOrWhiteSpace(drv["PaidDate"].ToString()) ? "-1" : drv["LineHeaderID"].ToString());<br> 
           btn.OnClientClick =
"if (!confirm('Are you sure you all information is correct for this employee?')) return false;";<br>
           btn.Style.Add(HtmlTextWriterStyle.MarginLeft,
"20px");<br>
           btn.CommandName =
"PayEmployee";<br>
           hi.Cells[hi.Cells.Count - 2].Controls.Add(btn);<br>
           btn.Click +=
new EventHandler(btnPayEmployee_Click);<br>
       }<br>
 }

However the btn.Click event isn't firing.  I've also tried the command name and using the radgrid Item command without success.  

Any advice?

4 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 01 Dec 2014, 11:45 AM
Hello Kyle,

I'm sending you two sample RadGrid web sites which I believe will prove very helpful for your current requirement. Please run the attached applications and let me know if they help you.


Regards,
Eyup
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
Kyle
Top achievements
Rank 1
answered on 01 Dec 2014, 05:37 PM
Hi Eyup,

Those didn't help but I was able to figure it out.

Essentially in the _ItemCreated I added the controls I was going to be working with (a button in this case).

//top header:
  if (e.Item is GridGroupHeaderItem && e.Item.GroupIndex.Split('_').Length == 1)
        {
                 GridGroupHeaderItem hi = e.Item as GridGroupHeaderItem;
                  Button btn = new Button();
                  btn.ID = "btnUpdateHeader";            
       }

Then in the ItemDatabound I could add the arguments:
  if (e.Item is GridGroupHeaderItem && e.Item.GroupIndex.Split('_').Length == 1)
        {
            GridGroupHeaderItem hi = e.Item as GridGroupHeaderItem;
            DataRowView drv = ((DataRowView)e.Item.DataItem);
            Button btn = (Button)hi.FindControl("btnUpdateHeader");
           btn.CommandArgument = drv["UserID"].ToString()         
        }

    protected void btnUpdateHeader_Click(object sender, EventArgs e)
    {
      // do stuff
}

Thanks though.






0
Kyle
Top achievements
Rank 1
answered on 01 Dec 2014, 05:38 PM
I forgot to show the adding of the button:

This goes in the  _ItemCreated:

  hi.Cells[hi.Cells.Count - 2].Controls.Add(btn);

0
Eyup
Telerik team
answered on 02 Dec 2014, 07:50 AM
Hello Kyle,

Thank you for sharing your approach with our community. The approach demonstrated in the RadGridGroupHeaderRadioButtonListEdited sample is also good and allows more advanced customization.

Regards,
Eyup
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.

 
Tags
Grid
Asked by
Kyle
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Kyle
Top achievements
Rank 1
Share this question
or