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

GridGroupByField disappear after insert groupheadertemplate

3 Answers 37 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joe
Top achievements
Rank 1
Joe asked on 26 Sep 2013, 09:57 AM

i had used GridGroupByField to display some information in group header.

as i need to add a checkbox to select all node/row, i had added a checkbox column in groupheadertemplate

but all the information in group header disappear after add the groupheadertemplate.

how can i solve it ? thanks.

               <telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="True" 
                    AllowMultiRowSelection="True" AllowPaging="True" AllowSorting="True" 
                    AutoGenerateColumns="False" CellSpacing="0" DataSourceID="ldsPayrollFlow" 
                    EnableAJAX="true" EnableAJAXLoadingTemplate="true" GridLines="None" 
                    LoadingTemplateTransparency="25" PageSize="100" Width="1180px">
  
                    <PagerStyle Mode="NumericPages"></PagerStyle>
                                   
                    <mastertableview datakeynames="SID" datasourceid="ldsPayrollFlow" 
                    grouploadmode="Client">
                        <commanditemsettings exporttopdftext="Export to Pdf"></commanditemsettings>
                        <rowindicatorcolumn>
                            <HeaderStyle Width="10px"></HeaderStyle>
                  
                        </rowindicatorcolumn>
                        <expandcollapsecolumn>
                            <HeaderStyle Width="10px"></HeaderStyle>
                  
                        </expandcollapsecolumn>
  
                        <groupbyexpressions>                                               
                        <telerik:GridGroupByExpression
                            <selectfields
                                <telerik:GridGroupByField FieldAlias="DisplayName" 
                                FieldName="DisplayName" HeaderText="Staff Name" HeaderValueSeparator="  : "></telerik:GridGroupByField
                            </selectfields
                            <groupbyfields
                                <telerik:GridGroupByField FieldName="DisplayName"></telerik:GridGroupByField
                            </groupbyfields>                         
                            </telerik:GridGroupByExpression
                        </groupbyexpressions
  
                        <groupheadertemplate>
                            <asp:CheckBox ID="GroupHeaderCheckBox" runat="server" 
                            OnClick="GroupToggleSelection(this);" ToggleType="CheckBox" ToolTip ="Select this staff">
                            </asp:CheckBox>     
                            <asp:Label ID="lb_staff_detail" runat="server" Text=""></asp:Label>                                                                                              
                        </groupheadertemplate>
  
                        <Columns>
  
                            <telerik:GridBoundColumn DataField="SID" HeaderText="SID" ReadOnly="True" 
                                SortExpression="SID" UniqueName="SID" Visible="false">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn AllowFiltering="true" DataField="StaffNo" 
                                HeaderStyle-Width="100" HeaderText="Staff Number" ReadOnly="True" 
                                SortExpression="StaffNo" UniqueName="StaffNo">
                                <ItemStyle BackColor="White" BorderColor="ActiveBorder" 
                                Font-Underline="false" ForeColor="Black" />
                            </telerik:GridBoundColumn>                            
                            <telerik:GridBoundColumn AllowFiltering="true" DataField="DisplayName" 
                                HeaderStyle-Width="100" HeaderText="Staff Name" ReadOnly="True" 
                                SortExpression="DisplayName" UniqueName="DisplayName"><ItemStyle 
                                BackColor="White" BorderColor="ActiveBorder" Font-Underline="false" 
                                ForeColor="black" />
                            </telerik:GridBoundColumn>                            
                            <telerik:GridBoundColumn AllowFiltering="true" DataField="Department" 
                                HeaderStyle-Width="100" HeaderText="Department" ReadOnly="True" 
                                SortExpression="Department" UniqueName="Department">
                                <ItemStyle BackColor="White" BorderColor="ActiveBorder" 
                                Font-Underline="false" ForeColor="Black" />
                            </telerik:GridBoundColumn>                            
                            <telerik:GridBoundColumn AllowFiltering="true" DataField="BasicSalaryMonthly" ItemStyle-CssClass="cellalignRight"
                                DataFormatString="{0:G}" HeaderStyle-Width="100" HeaderText="Basic Salary" ItemStyle-HorizontalAlign="Right" 
                                ReadOnly="True" SortExpression="BasicSalaryMonthly" 
                                UniqueName="BasicSalaryMonthly"><ItemStyle BackColor="White" 
                                BorderColor="ActiveBorder" Font-Underline="false" ForeColor="Black" />
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn AllowFiltering="true" DataField="AllowanceName" 
                                HeaderStyle-Width="150" HeaderText="Allowance Name" ReadOnly="True" 
                                SortExpression="AllowanceName" UniqueName="AllowanceName"><ItemStyle 
                                BackColor="White" BorderColor="ActiveBorder" Font-Underline="false" 
                                ForeColor="Black" />
                            </telerik:GridBoundColumn>                            
                            <telerik:GridBoundColumn AllowFiltering="true" DataField="AllowanceAmount" 
                                DataFormatString="{0:G}" HeaderStyle-Width="100" HeaderText="Amount" ItemStyle-HorizontalAlign="Right"
                                ReadOnly="True" SortExpression="AllowanceAmount" UniqueName="AllowanceAmount"><ItemStyle 
                                BackColor="White" BorderColor="ActiveBorder" Font-Underline="false" 
                                ForeColor="Black" />
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn AllowFiltering="true" DataField="UpdateDate" DataFormatString="{0:dd-MMM-yyyy}" 
                                HeaderStyle-Width="100" HeaderText="Last Updated Date" ReadOnly="True" DataType="System.DateTime" 
                                SortExpression="UpdateDate" UniqueName="UpdateDate"><ItemStyle 
                                BackColor="White" BorderColor="ActiveBorder" Font-Underline="false" 
                                ForeColor="Black" />
                            </telerik:GridBoundColumn>                            
                            <telerik:GridBoundColumn AllowFiltering="true" DataField="FlowDate" DataFormatString="{0:dd-MMM-yyyy}" 
                                HeaderStyle-Width="100" HeaderText="Last Flow Date" ReadOnly="True" DataType="System.DateTime" 
                                SortExpression="FlowDate" UniqueName="FlowDate"><ItemStyle 
                                BackColor="White" BorderColor="ActiveBorder" Font-Underline="false" 
                                ForeColor="Black" />
                            </telerik:GridBoundColumn>                            
                            <telerik:GridClientSelectColumn Display="false" HeaderStyle-Width="10" 
                                UniqueName="ClientSelectColumn" Visible="true"
                                </telerik:GridClientSelectColumn>
  
  
                            </Columns>
                  
                    </mastertableview>
                                <clientsettings>
                <selecting allowrowselect="true"></selecting>
                <ClientEvents OnRowSelecting="Selecting" />
<%--                <resizing allowcolumnresize="True" allowrowresize="True" 
                    enablerealtimeresize="True" resizegridoncolumnresize="False"></resizing>--%>
            </clientsettings>
                </telerik:RadGrid>

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 26 Sep 2013, 11:52 AM
Hi Joe,

Please add the GroupHeaderTemplate from code behind as follows.

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
   {
       if (e.Item is GridGroupHeaderItem)
       {
           GridGroupHeaderItem headeritem = (GridGroupHeaderItem)e.Item;
           CheckBox chk = new CheckBox();
           if (headeritem.GroupIndex.Split('_').Length == 1)
           {
               string text = headeritem.DataCell.Text;
               (headeritem as GridGroupHeaderItem).DataCell.Controls.Add(chk);
               chk.Text = text;
               chk.CheckedChanged+=new EventHandler(chk_CheckedChanged); //CheckChanged event being declared
           }
       }
   }


Thanks,
Shinu
0
Joe
Top achievements
Rank 1
answered on 27 Sep 2013, 01:33 AM
thanks for your reply.

it had return the following error msg :

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC32022: 'Public Event CheckedChanged(sender As Object, e As System.EventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.

Source Error:

Line 198:                TryCast(headeritem, GridGroupHeaderItem).DataCell.Controls.Add(chk)
Line 199:                chk.Text = text
Line 200: chk.CheckedChanged += New EventHandler(chk_CheckedChanged)Line 201:            End If
Line 202:        End If


Moreover, as i need to call javascript function in aspx page.
can I just data bound all need information to the label "lb_staff_detail" in code behind ?
how can i do this ? thanks
0
Shinu
Top achievements
Rank 1
answered on 27 Sep 2013, 04:55 AM
Hi Joe,

Please correct the code as below.

VB:
Protected Sub RadGrid1_ItemDataBound(sender As Object, e As GridItemEventArgs)
       If TypeOf e.Item Is GridGroupHeaderItem Then
           Dim headeritem As GridGroupHeaderItem = DirectCast(e.Item, GridGroupHeaderItem)
           Dim chk As New CheckBox()
           If headeritem.GroupIndex.Split("_"c).Length = 1 Then
               Dim text As String = headeritem.DataCell.Text
               TryCast(headeritem, GridGroupHeaderItem).DataCell.Controls.Add(chk)
               chk.Text = text
               chk.AutoPostBack = True
               AddHandler chk.CheckedChanged, AddressOf chk_CheckedChanged             
           End If
       End If
   End Sub
 
Private Sub chk_CheckedChanged(sender As Object, e As System.EventArgs)
     ' Your code
   End Sub

Thanks,
Shinu
Tags
Grid
Asked by
Joe
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Joe
Top achievements
Rank 1
Share this question
or