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

Hide Expand nestedviewtemplate

5 Answers 180 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Reeba
Top achievements
Rank 1
Reeba asked on 30 Mar 2011, 06:31 PM
<telerik:RadGrid ID="rgStatus" runat="server" AutoGenerateColumns="False" BorderStyle="None" Width="100%">
                                      <HeaderStyle HorizontalAlign="Left" Font-Bold="true" BorderWidth="0" BorderStyle="None" />
                                      <ItemStyle BorderStyle="None" BorderWidth="0" />
                                      <AlternatingItemStyle BorderStyle="None" BorderWidth="0" />
                                      <ClientSettings EnablePostBackOnRowClick="false"></ClientSettings>
                                      <MasterTableView>
                                          <Columns>
                                              <telerik:GridTemplateColumn ItemStyle-Width="250" DataField="StsExternalDesc" UniqueName="StsExternalName" HeaderText="Status">
                                                  <ItemTemplate>
                                                      <asp:Label ID="lblStatus" runat="server" Text='<%#DataBinder.Eval(Container, "DataItem.StsExternalDesc") %>' />
                                                  </ItemTemplate>
                                              </telerik:GridTemplateColumn>
                                              <telerik:GridBoundColumn ItemStyle-Width="125" DataField="StsDateTime" HeaderText="Date" />
                                              <telerik:GridBoundColumn ItemStyle-Width="99" DataField="StsDateTime" HeaderText="Time" />
                                          </Columns>
                                          <NestedViewTemplate>                               
                                               <table border="0" cellpadding="2" cellspacing="0">
                                                   <tr id="trStsDesc1">                                        
                                                      <td><asp:Label ID="lblStsDesc1" runat="server" Text='<%# Eval("StsDesc1") %>'></asp:Label></td>
                                                   </tr>
                                                  <tr id="trStsDesc2">
                                                      <td><asp:Label ID="lblStsDesc2" runat="server" Text='<%# Eval("StsDesc2") %>'></asp:Label></td>
                                                  </tr>
                                              </table>
                                            
                                          </NestedViewTemplate>
                                      </MasterTableView>
                                         
                                  </telerik:RadGrid>
I see alot of articles on this subject but I am still not able to get it to work. I have   a gridview with 3 columns status,date,time.
For each status there could be some notes associated with it, which if there are notes then show in the nestedtemplate.My issue is if there are no notes I don't want to see the image to expand. If there is a note for a particular status then show the image to expand.Right now my code shows the expand image even if the notes are blank.

 

5 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 31 Mar 2011, 01:06 PM
Hi Reeba,

Please, take a look at this help article that explains how to hide expand/collapse images when no records and let us know if any of your questions remain unanswered afterwards.

Best wishes,
Pavlina
the Telerik team
0
Reeba
Top achievements
Rank 1
answered on 31 Mar 2011, 01:33 PM
<telerik:RadGrid ID="rgStatus" runat="server" AutoGenerateColumns="False" BorderStyle="None" Width="100%" OnPreRender="rgStatus_PreRender" >
                                        <HeaderStyle HorizontalAlign="Left" Font-Bold="true" BorderWidth="0" BorderStyle="None" />
                                        <ItemStyle BorderStyle="None" BorderWidth="0" />
                                        <AlternatingItemStyle BorderStyle="None" BorderWidth="0" />
                                        <ClientSettings EnablePostBackOnRowClick="false"></ClientSettings>
                                        <MasterTableView HierarchyLoadMode="ServerBind" HierarchyDefaultExpanded="true">
                                            <Columns>
                                                <telerik:GridTemplateColumn ItemStyle-Width="250" DataField="StsExternalDesc" UniqueName="StsExternalName" HeaderText="Status">
                                                    <ItemTemplate>
                                                        <asp:Label ID="lblStatus" runat="server" Text='<%#DataBinder.Eval(Container, "DataItem.StsExternalDesc") %>' />
                                                    </ItemTemplate>
                                                </telerik:GridTemplateColumn>
                                                <telerik:GridBoundColumn ItemStyle-Width="125" DataField="StsDateTime" HeaderText="Date" />
                                                <telerik:GridBoundColumn ItemStyle-Width="99" DataField="StsDateTime" HeaderText="Time" />
                                            </Columns>
                                             
                                            <NestedViewTemplate>                              
                                             
                                                 <table border="0" cellpadding="2" cellspacing="0">
                                                     <tr id="trStsDesc1">                                        
                                                        <td><asp:Label ID="lblStsDesc1" runat="server" Text='<%# Eval("StsDesc1") %>'></asp:Label></td>
                                                     </tr>
                                                    <tr id="trStsDesc2">
                                                        <td><asp:Label ID="lblStsDesc2" runat="server" Text='<%# Eval("StsDesc2") %>'></asp:Label></td>
                                                    </tr>
                                                </table>
                                           
                                            </NestedViewTemplate>
                                              
                                        </MasterTableView>
                                           
                                    </telerik:RadGrid>
' Protected Sub rgStatus_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles rgStatus.PreRender
    '        Dim rgStatsInfo As RadGrid = DirectCast(sender, RadGrid)
    '       HideExpandColumnRecursive(rgStatsInfo.MasterTableView)
  
     For Each item As GridNestedViewItem In rgStatus.MasterTableView.GetItems(GridItemType.NestedView)  
    '// loop through the nested items of a NestedView TemplateRJ
  
      
    For Each nestedView As GridTableView In item.NestedTableViews
    If item.NestedTableViews.Count = 0 Then RJ
  
    Dim cell As TableCell = item.ParentItem("ExpandColumn")
    'cell.Controls(0).Visible = False
    'item.Visible = False
    Dim parentitem As GridDataItem = DirectCast(item.ParentItem, GridDataItem) 
    Dim cell As TableCell = parentitem("ExpandColumn"
    cell.Controls.Clear()
  
    End If 
    Next 
  
    End Sub
In the example you send there were detail tables.In my code I am not using detail tables. Still not able to figure what I am not doing right.
0
Pavlina
Telerik team
answered on 01 Apr 2011, 01:54 PM
Hi Reeba,

You can try the approach suggested by Princy in the following forum thread:
http://www.telerik.com/community/forums/aspnet-ajax/grid/how-to-hide-expand-cell-when-record-not-found.aspx

Greetings,
Pavlina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Reeba
Top achievements
Rank 1
answered on 01 Apr 2011, 02:54 PM
Protected Sub rgStatus_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles rgStatus.PreRender
        ' loop through the nested items of a NestedView Template
        For Each item As GridNestedViewItem In rgStatus.MasterTableView.GetItems(GridItemType.NestedView)
            Dim lbl_1 As Label = DirectCast(item.FindControl("lblStsDesc1"), Label)
            Dim lbl_2 As Label = DirectCast(item.FindControl("lblStsDesc2"), Label)
  
            If (Trim(lbl_1.Text) = Nothing And Trim(lbl_2.Text) = Nothing) Then
                Dim parentitem As GridDataItem = DirectCast(item.ParentItem, GridDataItem)
                Dim cell As TableCell = parentitem("ExpandColumn")
                cell.Controls.Clear()
            End If
        Next
  
    End Sub
Thanks I was finally able to find what I was doing wrong.I have posted my code for anyone who might find it useful.It works perfectly for me now.
0
Pavlina
Telerik team
answered on 04 Apr 2011, 08:35 AM
Hi Reeba,

I am glad you managed to make the things work. In case you experience further problems or you have additional questions, I will be happy to assist.

All the best,
Pavlina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
General Discussions
Asked by
Reeba
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Reeba
Top achievements
Rank 1
Share this question
or