Radgrid Merge rows to the whole column.

6 posts, 0 answers
  1. m chotu
    m chotu avatar
    10 posts
    Member since:
    Dec 2009

    Posted 20 Jan 2010 Link to this post

    Hi Telerik team;

    I am trying to achive the following thing in my radgrid.  I have a mastergrid and a detail table in my aspx.  In the detail table I need to set the rowspan of the first column such a way that there is only 1 cell in that column with text.  I have enclosed the jpg that I am trying to achieve.  I tried using this code in the onItemDataBound event:  But I am not getting the desired result.  I have also enclosed my actual result.  Could you please help?  

    Thanks in advance,

    Meera 

    //Aspx

     

    <

     

    telerik:RadGrid ID="viewGrid" runat="server" ActiveItemStyle-BorderColor="ActiveBorder"

     

     

     

     

     

     

    ShowStatusBar="True" AllowSorting="true" ItemStyle-BorderWidth="1px" OnSortCommand="viewGrid_Sort"

     

     

     

     

     

     

    MasterTableView-ExpandCollapseColumn-CollapseImageUrl="~/App_Themes/Images/Content/collapse.gif"

     

     

    MasterTableView-ExpandCollapseColumn-ItemStyle-CssClass="textalignleft"

     

     

    MasterTableView-ExpandCollapseColumn-ButtonType="ImageButton"

     

     

    MasterTableView-ExpandCollapseColumn-ExpandImageUrl="~/App_Themes/Images/Content/expand.gif"

     

     

     

     

     

     

    OnUpdateCommand="viewGrid_UpdateCommand" Width="900px"

     

     

     

     

     

     

    MasterTableView-ExpandCollapseColumn-ItemStyle-HorizontalAlign="Center" OnItemCreated="viewGrid_ItemCreated"

     

     

     

     

     

     

    MasterTableView-ExpandCollapseColumn-ItemStyle-VerticalAlign="Middle" OnItemDataBound="viewGrid_DataBound"

     

     

     

     

     

     

    MasterTableView-ExpandCollapseColumn-ItemStyle-Width="2%" OnDetailTableDataBind="viewGrid_DetailTableDataBind"

     

     

    OnNeedDataSource="viewGrid_NeedDataSource" OnPreRender="viewGrid_PreRender"

     

     

    OnInsertCommand="viewGrid_InsertCommand" AllowMultiRowEdit="false">

     

     

     

     

     

     

    <MasterTableView AutoGenerateColumns="False" HierarchyLoadMode="ServerBind"

     

     

     

     

     

     

    DataKeyNames="DomainName,ParentDomainValue" Name="Master" >

     

     

     

     

     

     

    <DetailTables>

     

     

     

     

     

     

    <telerik:GridTableView DataKeyNames="DomainName,ParentDomainName,ParentDomainValue,DomainValue" Name="DomainLabel"

     

     

    AutoGenerateColumns="false" BorderStyle="None" ItemStyle-BorderWidth="0px" AllowSorting="false"

     

     

    ShowHeader="false" Width="900px"

     

     

     

     

     

     

    CommandItemDisplay="Top" EditMode="InPlace">

     

     

     

     

     

     

    <ParentTableRelation>

     

     

     

     

     

     

    <telerik:GridRelationFields DetailKeyField="DomainName" MasterKeyField="DomainName" />

     

     

     

     

     

     

    </ParentTableRelation>

     

     

     

     

     

     

    <CommandItemSettings AddNewRecordText="<%$ Resources:DomainAdmin, locAddDomainValue %>" />

     

     

     

     

     

     

    <Columns>

     

     

     

     

     

     

    <telerik:GridTemplateColumn UniqueName="DomainLabelcol" >

     

     

     

     

     

     

    <ItemTemplate>

     

     

     

     

     

     

    <asp:Label ID="plSubject" runat="server" Text="Domain Values" />

     

     

     

     

     

     

    </ItemTemplate>

     

     

     

     

     

     

    <ItemStyle Width="150px" Wrap="false" HorizontalAlign="Left" CssClass="panelstyle"

     

     

    ForeColor="#62267f" Font-Bold="true"/>

     

     

     

     

     

     

    </telerik:GridTemplateColumn>

     

     

     

     

     

     

    <telerik:GridBoundColumn UniqueName="DomainValue" DataType="System.String"

     

     

     

     

     

     

    DataField="DomainValue" ColumnEditorID="GridTextBoxColumnEditor1"

     

     

     

     

     

     

    ItemStyle-HorizontalAlign="Left"

     

     

     

     

     

     

    ItemStyle-Wrap="false"

     

     

     

     

     

     

    ItemStyle-Width="300px">

     

     

     

     

     

     

    </telerik:GridBoundColumn>

     

     

     

     

     

     

    <telerik:GridCheckBoxColumn DataField="ActiveFlag" UniqueName="ActiveFlag"

     

     

    DataType="System.Boolean"

     

     

    ItemStyle-HorizontalAlign="Left"

     

     

     

     

     

     

    ItemStyle-Wrap="false"

     

     

     

     

     

     

    ItemStyle-Width="20px">

     

     

    </telerik:GridCheckBoxColumn>

     

     

     

     

     

     

    <telerik:GridTemplateColumn UniqueName="DomainLabelcol" >

     

     

     

     

     

     

    <ItemTemplate>

     

     

     

     

     

     

    <asp:Label ID="lblActive" Text="Active" runat="server" CssClass="ActiveLabelStyle" />

     

     

     

     

     

     

    </ItemTemplate>

     

     

     

     

     

     

    <ItemStyle Width="130px" Wrap="false" HorizontalAlign="Left" />

     

     

     

     

     

     

    </telerik:GridTemplateColumn>

     

     

     

     

     

     

    <telerik:GridEditCommandColumn ButtonType="ImageButton"

     

     

    EditImageUrl="../App_Themes/Images/Buttons/domain_pur_edit.gif"

     

     

     

     

     

     

    InsertImageUrl="../App_Themes/Images/Buttons/domain_gr_insert.gif"

     

     

     

     

     

     

    CancelImageUrl="../App_Themes/Images/Buttons/domain_gr_cancel.gif"

     

     

     

     

     

     

    UpdateImageUrl="../App_Themes/Images/Buttons/domain_gr_update.gif"

     

     

     

     

     

     

    UniqueName="EditDomainValueColumn"

     

     

     

     

     

     

    ItemStyle-HorizontalAlign="Right"

     

     

     

     

     

     

    ItemStyle-Wrap="false"

     

     

     

     

     

     

    ItemStyle-Width="200px">

     

     

     

     

     

     

    </telerik:GridEditCommandColumn>

     

     

     

     

     

     

    <telerik:GridCheckBoxColumn DataField="EditableFlag" UniqueName="EditFlag"

     

     

    DataType="System.Boolean" Visible="false" >

     

     

    </telerik:GridCheckBoxColumn>

     

     

     

     

     

     

     

    </Columns>

     

     

     

     

     

     

    </telerik:GridTableView>

     

     

     

     

     

     

    </DetailTables>

     

     

     

     

     

     

    <Columns>

     

     

     

     

     

     

    <telerik:GridBoundColumn UniqueName="DomainName" DataType="System.String" HeaderText="<%$ Resources:DomainAdmin, locDomainName %>"

     

     

     

     

     

     

    DataField="DomainName" SortExpression="DomainName"

     

     

    ItemStyle-HorizontalAlign="Left"

     

     

     

     

     

     

    HeaderStyle-Width="200px" HeaderStyle-HorizontalAlign="Left" ItemStyle-Wrap="false"

     

     

     

     

     

     

    HeaderStyle-Font-Bold="true" HeaderStyle-ForeColor="#62267f" ItemStyle-Width="200px"

     

     

     

     

     

     

    SortAscImageUrl="~/App_Themes/Images/Buttons/arrow_sort_up.png"

     

     

    SortDescImageUrl="~/App_Themes/Images/Buttons/arrow_sort_down.png"

     

     

     

     

     

     

    >

     

     

     

     

     

     

    </telerik:GridBoundColumn>

     

     

     

     

     

     

    <telerik:GridBoundColumn UniqueName="ParentDomainName" DataType="System.String"

     

     

     

     

     

     

    HeaderText="<%$ Resources:DomainAdmin, locParentDomainName %>" DataField="ParentDomainName"

     

     

    SortExpression="ParentDomainName"

     

     

     

     

     

     

    ItemStyle-HorizontalAlign="Left"

     

     

     

     

     

     

    HeaderStyle-Width="300px" HeaderStyle-HorizontalAlign="Left" ItemStyle-Wrap="false"

     

     

     

     

     

     

    HeaderStyle-Font-Bold="true" HeaderStyle-ForeColor="#62267f" ItemStyle-Width="300px"

     

     

     

     

     

     

    SortAscImageUrl="~/App_Themes/Images/Buttons/arrow_sort_up.png"

     

     

    SortDescImageUrl="~/App_Themes/Images/Buttons/arrow_sort_down.png">

     

     

    </telerik:GridBoundColumn>

     

     

     

     

     

     

    <telerik:GridBoundColumn UniqueName="ParentDomainValue" DataType="System.String" HeaderText="<%$ Resources:DomainAdmin, locParentDomainValue %>"

     

     

     

     

     

     

    DataField="ParentDomainValue" SortExpression="ParentDomainValue"

     

     

     

     

     

     

    ItemStyle-HorizontalAlign="Left"

     

     

     

     

     

     

    HeaderStyle-Width="300px" HeaderStyle-HorizontalAlign="Left" ItemStyle-Wrap="false"

     

     

     

     

     

     

    HeaderStyle-Font-Bold="true" HeaderStyle-ForeColor="#62267f" ItemStyle-Width="300px"

     

     

     

     

     

     

    SortAscImageUrl="~/App_Themes/Images/Buttons/arrow_sort_up.png"

     

     

    SortDescImageUrl="~/App_Themes/Images/Buttons/arrow_sort_down.png">

     

     

     

     

     

     

    </telerik:GridBoundColumn>

     

     

     

     

     

     

    </Columns>

     

     

     

     

     

     

    <AlternatingItemStyle Wrap="false"/>

     

     

     

     

     

     

    <ItemStyle Wrap="false"/>

     

     

     

     

     

     

    <RowIndicatorColumn Visible="False">

     

     

     

     

     

     

    <HeaderStyle Width="20px" />

     

     

     

     

     

     

    </RowIndicatorColumn>

     

     

     

     

     

     

    <ExpandCollapseColumn ButtonType="ImageButton">

     

     

     

     

     

     

    </ExpandCollapseColumn>

     

     

     

     

     

     

    <EditFormSettings>

     

     

     

     

     

     

    <PopUpSettings ScrollBars="None" />

     

     

     

     

     

     

    </EditFormSettings>

     

     

     

     

     

     

    </MasterTableView>

     

     

     

     

     

     

    </telerik:RadGrid>

     

     

     



     

     

    protected

     

    void viewGrid_DataBound(object source, Telerik.Web.UI.GridItemEventArgs e)

     

    {

     

    if (!(e.Item is GridDataInsertItem))

     

    {

     

    if ((e.Item is GridDataItem) && (e.Item.OwnerTableView.Name == "DomainLabel"))

     

    {

        //Merge rows

     

     

     

        GridTableView tv = (GridTableView)e.Item.OwnerTableView;

     

     

        for (int rowIndex = tv.Items.Count - 2; rowIndex >= 0; rowIndex--)

     

        {

     

            GridDataItem row = tv.Items[rowIndex];

     

     

            GridDataItem previousRow = tv.Items[rowIndex + 1];

     

     

            if (row["DomainLabelcol"].Text == previousRow["DomainLabelcol"].Text)

     

            {

                row[

    "DomainLabelcol"].RowSpan = 2;

     

                previousRow[

    "DomainLabelcol"].Visible = false;

     

                previousRow[

    "DomainLabelcol"].Text = "&nbsp;";

     

            }

        }
    }

  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 21 Jan 2010 Link to this post

    Hello Meera,

    Try out the following code in the PreRender event of the grid and see if it helps:
    c#:
     protected void RadGrid1_PreRender(object sender, EventArgs e) 
        { 
           foreach (GridDataItem dataItem in RadGrid1.Items) 
            { 
                if ((dataItem.OwnerTableView.Name == "DomainLabel")) 
                { 
                    //Merge rows 
                    GridTableView tv = (GridTableView)dataItem.OwnerTableView; 
                    for (int rowIndex = tv.Items.Count - 2; rowIndex >= 0; rowIndex--) 
                    { 
                        GridDataItem row = tv.Items[rowIndex]; 
                        GridDataItem previousRow = tv.Items[rowIndex + 1]; 
                        if (row["DomainLabelcol"].Text == previousRow["DomainLabelcol"].Text) 
                        { 
                            row["DomainLabelcol"].RowSpan = previousRow["DomainLabelcol"].RowSpan < 2 ? 2 : previousRow["DomainLabelcol"].RowSpan + 1; 
                            previousRow["DomainLabelcol"].Visible = false
                            previousRow["DomainLabelcol"].Text = "&nbsp;"
                        } 
                    } 
                } 
            } 
       } 

    Thanks
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. m chotu
    m chotu avatar
    10 posts
    Member since:
    Dec 2009

    Posted 21 Jan 2010 Link to this post

    Thanks Princy!  That worked really well for me.  Thanks for your help.

    Meera
  5. Hector Hernandez
    Hector Hernandez avatar
    45 posts
    Member since:
    Oct 2009

    Posted 17 Jun 2013 Link to this post

    Dear Princy, i see these example, and also work for me, but the grid semms to be without lines
    here an image, is there a way to fix that

    thanks in advance

     
  6. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 17 Jun 2013 Link to this post

    Hi,

    Please try setting GridLines="Both" .

    ASPX:
    <telerik:RadGrid ID="RadGrid1" runat="server" GridLines="Both">
    . . . . . . .
     </telerik:RadGrid>

    Thanks,
    Shinu
  7. Hector Hernandez
    Hector Hernandez avatar
    45 posts
    Member since:
    Oct 2009

    Posted 17 Jun 2013 Link to this post

    hi Shinu
    i was triying that but dosen't work
    here is how is my Grid

    <telerik:RadGrid runat="server" ID="GrdAnalEst" PageSize="20" 
                                    AutoGenerateColumns="false" Width="100%" AllowSorting="true" GridLines="Both"
                                    AllowPaging="true">
                                    <PagerStyle Mode="NextPrevAndNumeric" NextPageText="Siguiente" 
                                  PrevPageText="Anterior" Position="Bottom" 
                                  PagerTextFormat="Change page: {4} &amp;nbsp;Pagina &lt;strong&gt;{0}&lt;/strong&gt; de &lt;strong&gt;{1}&lt;/strong&gt;, registros &lt;strong&gt;{2}&lt;/strong&gt; a &lt;strong&gt;{3}&lt;/strong&gt; de &lt;strong&gt;{5}&lt;/strong&gt;." 
                                  PageSizeLabelText="Regitros" />
                                <MasterTableView DataKeyNames="CODPROPIEDAD,CODSOLICITANTE,CODPLAN,UMANEJO,area,PARCELA,VOLH" NoMasterRecordsText="No Hay Inventario Ingresado" ShowFooter="true" Name="Labeles">
                                    <Columns>
                                        <telerik:GridBoundColumn DataField="CODPROPIEDAD" Visible="false" HeaderText="Codigo" HeaderStyle-Width="75px">
                                            <HeaderStyle Width="225px"></HeaderStyle>
                                        </telerik:GridBoundColumn> 
                                        <telerik:GridBoundColumn DataField="CODSOLICITANTE" Visible="false" HeaderText="Codigo" HeaderStyle-Width="75px">
                                            <HeaderStyle Width="225px"></HeaderStyle>
                                        </telerik:GridBoundColumn> 
                                        <telerik:GridBoundColumn DataField="CODPLAN" Visible="false" HeaderText="Codigo" HeaderStyle-Width="75px">
                                            <HeaderStyle Width="225px"></HeaderStyle>
                                        </telerik:GridBoundColumn> 
                                        <telerik:GridBoundColumn DataField="UMANEJO" HeaderText="Umanejo" HeaderStyle-Width="100px"  FooterText="Total (mt³)" FooterStyle-Font-Bold="true" >
                                            <HeaderStyle Width="100px"></HeaderStyle>
                                        </telerik:GridBoundColumn>    
                                       <telerik:GridBoundColumn DataField="area" HeaderText="Area" HeaderStyle-Width="100px"   >
                                            <HeaderStyle Width="100px"></HeaderStyle>
                                        </telerik:GridBoundColumn> 
                                        <telerik:GridBoundColumn DataField="PARCELA" HeaderText="Parcela" HeaderStyle-Width="100px"   >
                                            <HeaderStyle Width="100px"></HeaderStyle>
                                        </telerik:GridBoundColumn> 
                                          <telerik:GridBoundColumn DataField="VOLH" HeaderText="Vol/Ha (mt³)" HeaderStyle-Width="100px" Visible="false"   >
                                            <HeaderStyle Width="100px"></HeaderStyle>
                                        </telerik:GridBoundColumn> 
                                        <telerik:GridTemplateColumn HeaderText="Volumen por h (mt³)"  UniqueName="VOLH" HeaderStyle-Width="100px" >
                                        <ItemTemplate>
                                            <telerik:RadNumericTextBox runat="server" ID="TxtVolGridEsta" Width="90px">
                                                <NumberFormat DecimalDigits="3" />
                                            </telerik:RadNumericTextBox>
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn> 
                                    </Columns>        
                                </MasterTableView>
                                <FilterMenu EnableTheming="true">
                                    <CollapseAnimation Duration="200" Type="OutQuint" />
                                </FilterMenu>
                            </telerik:RadGrid>
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017