Grid / ListView/DataList View with Grouping

6 posts, 0 answers
  1. Ali
    Ali avatar
    24 posts
    Member since:
    Apr 2010

    Posted 14 Sep 2012 Link to this post

    Hi,
    I am trying to use RadGrid as ListView layout and was able to follow the demo below to achieve the results.

    Grid / ListView/DataList View:
    http://demos.telerik.com/aspnet-ajax/grid/examples/programming/listview/defaultcs.aspx 

    Now, I need to be able to use "Grouping" [using ContactTitle:] so that all the ListView items are shown under corresponding Grouping.
    Is it possible and if so how?

    Thanks for your help.
    http://www.megasearches.com/ 
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 14 Sep 2012 Link to this post

    Hi,

    You can set GridGroupByExpression as shown below.
    aspx:
    <GroupByExpressions>
         <telerik:GridGroupByExpression>
                <SelectFields>
                      <telerik:GridGroupByField FieldName="ContactTitle" />
                </SelectFields>
                  <GroupByFields>
                         <telerik:GridGroupByField FieldName="ContactTitle"  />
                 </GroupByFields>
         </telerik:GridGroupByExpression>
    </GroupByExpressions>
    Also check the following demo which explains more about grouping.
    Grid / Outlook-style Grouping

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Ali
    Ali avatar
    24 posts
    Member since:
    Apr 2010

    Posted 15 Sep 2012 Link to this post

    Hi,
    I tried the <GroupByExpressions> but it did not work quite the way I want. Please see the attached images "gridlayout_current.jpg" and "gridlayout_expected.jpg".

    ---------------------------------------------------------------------- 
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="MainGrid_Box.ascx.cs" Inherits="_Default_MainGrid_Box" %>
     
    <telerik:RadGrid ID="RadGrid_r2bweb_Box" GridLines="None" runat="server" AllowSorting="true" AllowPaging="false" DataSourceID="SqlDataSource_r2bweb_Box">
        <PagerStyle Mode="NextPrevAndNumeric" AlwaysVisible="true"/>
        <MasterTableView Width="100%" CommandItemDisplay="Top" DataKeyNames="url_id"
            DataSourceID="SqlDataSource_r2bweb_Box" HorizontalAlign="NotSet" AutoGenerateColumns="true"
            GroupLoadMode="Client" GroupsDefaultExpanded="true" TableLayout="Fixed">
            <GroupHeaderTemplate>
                <asp:CheckBox ID="CheckBox_Main_Box" runat="server" onclick="CheckAll(this);" />
                <asp:Label runat="server" ID="r2b_GroupingHeader_Main_Box" Text='<%# " lst_name(s): "+Eval("lst_name") %>'
                Visible='<%# ((((GridGroupHeaderItem)Container).AggregatesValues["lst_name"]) != null)%>'></asp:Label>
            </GroupHeaderTemplate>
            <GroupByExpressions>
                <telerik:GridGroupByExpression>
                    <SelectFields>
                        <telerik:GridGroupByField FieldAlias="lst_name" FieldName="lst_name"></telerik:GridGroupByField>
                    </SelectFields>
                    <GroupByFields>
                        <telerik:GridGroupByField FieldName="lst_name" SortOrder="Descending"></telerik:GridGroupByField>
                    </GroupByFields>
                </telerik:GridGroupByExpression>
            </GroupByExpressions>
            <ItemTemplate>
                <%# (((GridItem)Container).ItemIndex != 0)? "</td></tr></table>" : "" %>
                <asp:Panel ID="r2bweb_panel" CssClass='<%# (((GridItem)Container).ItemType == GridItemType.Item)? "item" : "alternatingItem" %>' HorizontalAlign="Center" runat="server">
                    <asp:Image ID="r2bweb_mySites" Style="float: left; text-align:center;" Width="50px" Height="50px" ImageUrl="~/Images/mySites.png" runat="server" AlternateText="My Site" />
                    <br />
                    <%# Eval("url_name")%>
                </asp:Panel>
            </ItemTemplate>   
        </MasterTableView>
        <ClientSettings AllowDragToGroup="false" AllowColumnsReorder="false" AllowRowsDragDrop="True"
        AllowGroupExpandCollapse="True">
            <Selecting AllowRowSelect="true" EnableDragToSelectRows="true" />
            <Resizing AllowRowResize="True" EnableRealTimeResize="false" ResizeGridOnColumnResize="false"            
            AllowColumnResize="True" AllowResizeToFit="true" ShowRowIndicatorColumn="false"
            ClipCellContentOnResize="false" />
            <Scrolling AllowScroll="false" UseStaticHeaders="True" SaveScrollPosition="true" />
        </ClientSettings>
    </telerik:RadGrid>
    <asp:SqlDataSource ID="SqlDataSource_r2bweb_Box" runat="server"
    ConnectionString="<%$ ConnectionStrings:r2bweb_ConnectionString %>"
        SelectCommand="SELECT a.[lst_id], b.[lst_name], a.[url_id], a.[urp_id], a.[usr_id], a.[cat_id], a.[url_isOpen], a.[url_type], a.[url_name], a.[url_address], a.[url_isLoginOrOpen], a.[url_username], a.[url_isSaveUsername], a.[url_isEnableUsername], a.[url_password], a.[url_isSavePassword], a.[url_isEnablePassword], a.[url_desc], a.[url_isSave] FROM [t_url] a INNER JOIN [t_myList] b ON a.[lst_id] = b.[lst_id]">
    </asp:SqlDataSource>
    ---------------------------------------------------------------------- 

    Your help regarding this will be highly appreciated.

    Thanks,
    http://www.megasearches.com/ 


  5. Tsvetina
    Admin
    Tsvetina avatar
    1873 posts

    Posted 19 Sep 2012 Link to this post

    Hello,

    The required layout cannot be achieved with a table-like structure like RadGrid's. You should rather use RadListView with grouping to achieve your goal:
    http://demos.telerik.com/aspnet-ajax/listview/examples/grouping/defaultcs.aspx

    Greetings,
    Tsvetina
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  6. Ali
    Ali avatar
    24 posts
    Member since:
    Apr 2010

    Posted 20 Sep 2012 Link to this post

    Hi Tsvetina,
    Thanks for your response. But my project requires that I use a RadGrid in both views not RadListView so that both the controls are the same but views are different. Is there any workaround to this?

    Once again, thanks for your help.
    http://www.megasearches.com/  

  7. Tsvetina
    Admin
    Tsvetina avatar
    1873 posts

    Posted 25 Sep 2012 Link to this post

    Hi,

    Your required layout cannot be achieved in a grouped RadGrid. A last option would be if you could use a hierarchical structure with a NestedViewTemplate but I assume this would make this RadGrid instance too different from the other.

    Kind regards,
    Tsvetina
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017