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

Ragrid - Detail Table - column header change dynamically.

1 Answer 98 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mani PC
Top achievements
Rank 1
Mani PC asked on 24 Jan 2011, 06:32 PM

Hello Experts,

I have nested radgrid using  detail tables.

I have check boxes in one of my nested grid as shown in my html code below.

when user selects checkbox and expands , i want the column header on the expanded grid to show different text.

for e.g -

if they select Inv checkbox and expand, i want InvoiceNo and Invoice Date as my column header.

if they select Rcpt checkbox and expand, i want ReceiptNo and Receipt Date as my column header.

any idea?

-------------------------

here is my html code:

<telerik:RadGrid ID="grdGetMatchMiniSetList" AllowMultiRowSelection="false" AllowMultiRowEdit="false"
                    runat="server" AllowSorting="True" AllowPaging="false" GridLines="Both" 
                    HierarchyLoadMode="client"  Width="900">
                    <MasterTableView AutoGenerateColumns="false" DataKeyNames="MiniSetID" >
                       
                        <AlternatingItemStyle BackColor="Gainsboro" />
                        <NoRecordsTemplate>no records retrieved</NoRecordsTemplate>
                        <ItemStyle Wrap="True" />
       
                        <Columns>
                       
                            <telerik:GridButtonColumn ConfirmText="Delete this record?" ConfirmDialogType="RadWindow" ConfirmTitle="Delete"
                                ButtonType="ImageButton" CommandName="Delete" Text="Delete" UniqueName="DeleteColumn" ImageUrl="~/Images/Delete.gif" HeaderText="">
                                <HeaderStyle HorizontalAlign="Center" Width="30px" />
                                <ItemStyle HorizontalAlign="Center" />
                            </telerik:GridButtonColumn>                                    
                            <telerik:GridBoundColumn DataField="MiniSetID" HeaderText="Mini Set" UniqueName="MiniSetID" HeaderStyle-Wrap="true" ReadOnly="True">
                                <HeaderStyle Width="110px" HorizontalAlign="Center" Font-Bold="True" />
                                <ItemStyle HorizontalAlign="Right" />
                            </telerik:GridBoundColumn> 
                             <telerik:GridBoundColumn DataField="InvoiceQty" HeaderText="Invoice Qty" UniqueName="InvoiceQty" HeaderStyle-Wrap="true" >
                                <HeaderStyle Width="110px" HorizontalAlign="Center" Font-Bold="True" />
                                <ItemStyle HorizontalAlign="Right" />
                            </telerik:GridBoundColumn> 
                             <telerik:GridBoundColumn DataField="ReceiptQty" HeaderText="Rcpt Qty" UniqueName="ReceiptQty" HeaderStyle-Wrap="true" ReadOnly="True">                                 
                                <HeaderStyle Width="80px" HorizontalAlign="Center" Font-Bold="True" />
                                <ItemStyle HorizontalAlign="Right" />
                            </telerik:GridBoundColumn> 
                             <telerik:GridBoundColumn DataField="QtyDifference" HeaderText="Qty Difference" UniqueName="QtyDifference" HeaderStyle-Wrap="true" ReadOnly="True">
                                <HeaderStyle Width="110px" HorizontalAlign="Center" Font-Bold="True" />
                                <ItemStyle HorizontalAlign="Right" />
                            </telerik:GridBoundColumn>                                                                    
                             <telerik:GridBoundColumn DataField="InvoiceCost" HeaderText="Invoice Cost" UniqueName="InvoiceCost" HeaderStyle-Wrap="true" ReadOnly="True">
                                <HeaderStyle Width="110px" HorizontalAlign="Center" Font-Bold="True" />
                                <ItemStyle HorizontalAlign="Right" />
                            </telerik:GridBoundColumn>                            
                            <telerik:GridBoundColumn DataField="ReceiptCost" HeaderText="ReceiptCost" UniqueName="ReceiptCost" HeaderStyle-Wrap="true" ReadOnly="True">
                                <HeaderStyle Width="110px" HorizontalAlign="Center" Font-Bold="True" />
                                <ItemStyle HorizontalAlign="Right" />
                            </telerik:GridBoundColumn>                            
                            <telerik:GridBoundColumn DataField="CostDifference" HeaderText="Cost Difference" UniqueName="CostDifference" HeaderStyle-Wrap="true" ReadOnly="True">
                                <HeaderStyle Width="110px" HorizontalAlign="Center" Font-Bold="True" />
                                <ItemStyle HorizontalAlign="Right" />
                            </telerik:GridBoundColumn>                                                                 
                    </Columns> 

                    <DetailTables>
                           
                       <telerik:GridTableView Name="grdStyleDetails" AutoGenerateColumns="false" DataKeyNames="StyleNum">
                                <Columns>
                                 
                                    <telerik:GridTemplateColumn HeaderText="Rcpt" UniqueName="SelectRcpt">
                                        <ItemTemplate>
                                            <asp:CheckBox ID="chkRcpt" runat="server" Checked="false" 
                                                />
                                        </ItemTemplate>
                                         <HeaderStyle Width="20px" Font-Bold="True" />
                                        <ItemStyle Width="20px" HorizontalAlign="Center" />
                                    </telerik:GridTemplateColumn>
                                   
                                    <telerik:GridTemplateColumn HeaderText="Inv" UniqueName="SelectInv">
                                        <ItemTemplate>
                                            <asp:CheckBox ID="chkInv" runat="server" Checked="false"
                                                 />
                                        </ItemTemplate>
                                         <HeaderStyle Width="20px" Font-Bold="True" />
                                        <ItemStyle Width="20px" HorizontalAlign="Center" />
                                    </telerik:GridTemplateColumn>
                                                                   
                                 <telerik:GridBoundColumn DataField="StyleNum" HeaderText="Style" UniqueName="StyleNum"
                                     HeaderStyle-Wrap="true" >
                                        <HeaderStyle Width="120px" HorizontalAlign="Center" Font-Bold="True" />
                                        <ItemStyle HorizontalAlign="Right" />
                                </telerik:GridBoundColumn>
                               
                                 <telerik:GridBoundColumn DataField="InvQty" HeaderText="Inv Qty" UniqueName="InvQty"
                                     HeaderStyle-Wrap="true" ReadOnly="True">
                                        <HeaderStyle Width="80px" HorizontalAlign="Center" Font-Bold="True" />
                                        <ItemStyle HorizontalAlign="Right" />
                                </telerik:GridBoundColumn> 
                               
                                 <telerik:GridBoundColumn DataField="RcptQty" HeaderText="Rcpt Qty" UniqueName="RcptQty"
                                     HeaderStyle-Wrap="true" ReadOnly="True">
                                        <HeaderStyle Width="80px" HorizontalAlign="Center" Font-Bold="True" />
                                        <ItemStyle HorizontalAlign="Right" />
                                </telerik:GridBoundColumn>

                                 <telerik:GridBoundColumn DataField="QtyDiff" HeaderText="Qty Diff" UniqueName="QtyDiff"
                                     HeaderStyle-Wrap="true" ReadOnly="True">
                                        <HeaderStyle Width="80px" HorizontalAlign="Center" Font-Bold="True" />
                                        <ItemStyle HorizontalAlign="Right" />
                                </telerik:GridBoundColumn>
                                                                                               
                                 <telerik:GridBoundColumn DataField="InvCost" HeaderText="Inv Cost" UniqueName="InvCost"
                                     HeaderStyle-Wrap="true" >
                                        <HeaderStyle Width="80px" HorizontalAlign="Center" Font-Bold="True" />
                                        <ItemStyle HorizontalAlign="Right" />
                                </telerik:GridBoundColumn> 
                                                    
                                 <telerik:GridBoundColumn DataField="RcptCost" HeaderText="Rcpt Cost" UniqueName="RcptCost"
                                     HeaderStyle-Wrap="true" ReadOnly="True">
                                        <HeaderStyle Width="110px" HorizontalAlign="Center" Font-Bold="True" />
                                        <ItemStyle HorizontalAlign="Right" />
                                </telerik:GridBoundColumn>

                                 <telerik:GridBoundColumn DataField="CostDiff" HeaderText="Cost Diff" UniqueName="CostDiff"
                                     HeaderStyle-Wrap="true" ReadOnly="True">
                                        <HeaderStyle Width="110px" HorizontalAlign="Center" Font-Bold="True" />
                                        <ItemStyle HorizontalAlign="Right" />
                                </telerik:GridBoundColumn>                                    
                                </Columns>
                               
                                <DetailTables>
                                    <telerik:GridTableView Name="grdReceiptInvoice" AutoGenerateColumns="false">
                                    <Columns>
                                        <telerik:GridBoundColumn DataField="RcptInvNo" HeaderText="Rcpt/Inv No" UniqueName="RcptInvNo"
                                             HeaderStyle-Wrap="true" ReadOnly="True">
                                                <HeaderStyle Width="110px" HorizontalAlign="Center" Font-Bold="True" />
                                                <ItemStyle HorizontalAlign="Right" />
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="RcptInvDate" HeaderText="Rcpt/Inv Date" UniqueName="RcptInvDate"
                                             HeaderStyle-Wrap="true" ReadOnly="True">
                                                <HeaderStyle Width="110px" HorizontalAlign="Center" Font-Bold="True" />
                                                <ItemStyle HorizontalAlign="Right" />
                                        </telerik:GridBoundColumn> 
                                        <telerik:GridBoundColumn DataField="Store" HeaderText="Store" UniqueName="Store"
                                             HeaderStyle-Wrap="true" ReadOnly="True">
                                                <HeaderStyle Width="110px" HorizontalAlign="Center" Font-Bold="True" />
                                                <ItemStyle HorizontalAlign="Right" />
                                        </telerik:GridBoundColumn> 
                                        <telerik:GridBoundColumn DataField="Qty" HeaderText="Qty" UniqueName="Qty"
                                             HeaderStyle-Wrap="true" ReadOnly="True">
                                                <HeaderStyle Width="110px" HorizontalAlign="Center" Font-Bold="True" />
                                                <ItemStyle HorizontalAlign="Right" />
                                        </telerik:GridBoundColumn> 
                                        <telerik:GridBoundColumn DataField="UnitCost" HeaderText="Unit Cost" UniqueName="UnitCost"
                                             HeaderStyle-Wrap="true" ReadOnly="True">
                                                <HeaderStyle Width="110px" HorizontalAlign="Center" Font-Bold="True" />
                                                <ItemStyle HorizontalAlign="Right" />
                                        </telerik:GridBoundColumn> 
                                        <telerik:GridBoundColumn DataField="ExtendedCost" HeaderText="Extended Cost" UniqueName="ExtendedCost"
                                             HeaderStyle-Wrap="true" ReadOnly="True">
                                                <HeaderStyle Width="110px" HorizontalAlign="Center" Font-Bold="True" />
                                                <ItemStyle HorizontalAlign="Right" />
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="RcptInvNoText" HeaderText="" UniqueName="RcptInvNoText" Display="False" /> 
                                        <telerik:GridBoundColumn DataField="RcptInvDateText" HeaderText="" UniqueName="RcptInvDateText" Display="False" /> 
                                    </Columns>   
                                    </telerik:GridTableView>
                                </DetailTables>
                               
                            </telerik:GridTableView>
                           
                    </DetailTables>
                               </MasterTableView>
                    <ClientSettings EnableRowHoverStyle="true">
                        <Selecting AllowRowSelect="True" />
                        <Scrolling ScrollHeight="300px" />
                        <Resizing></Resizing>
                        <ClientEvents OnRowClick="OnMatchRowSelectedChanged" />
                    </ClientSettings>
                </telerik:RadGrid>

 

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 25 Jan 2011, 09:42 AM
Hello Mani,

The following code snippet shows hoe to achieve this.

C#:
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
       if (e.CommandName == RadGrid.ExpandCollapseCommandName && e.Item.OwnerTableView.Name == "grdStyleDetails")
        {
            GridTableView table=(GridTableView)e.Item.OwnerTableView;
            foreach (GridDataItem item in table.Items)
            {
                CheckBox chkbox = (CheckBox)item.FindControl("chkInv");
                if (chkbox.Checked)
                {
                    GridTableView tableView = (GridTableView)item.ChildItem.NestedTableViews[0];
                    tableView.GetColumn("RcptInvNo").HeaderText = "InvoiceNo"; //
                    tableView.Rebind();
                }
            }
 
        }
    }

Thanks,
Princy.
Tags
Grid
Asked by
Mani PC
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Share this question
or