Conditional Format with e.item.hasChildItems

4 posts, 0 answers
  1. armando
    armando avatar
    4 posts
    Member since:
    Sep 2008

    Posted 14 Sep 2011 Link to this post

    Hi, I need some of help

    I have a grid master / detail, but I need to change the color of the row if I have information in the detail
    Currently I have this in my code


    Protected Sub RadGridPEDG_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGridPEDG.ItemCreated
            Dim tableName As String
            tableName = e.Item.OwnerTableView.Name
             
            If (e.Item.HasChildItems = true ) Then
                 Dim dataBoundItem As GridDataItem = e.Item
                 dataBoundItem.BackColor= Drawing.Color.Red
                   
            End If
    end  Sub

    But not working

    Thanks !!
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 15 Sep 2011 Link to this post

    Hello Armando,

    Try the following code snippet in the prerender event.
    C#:
    Protected Sub RadGrid1_PreRender(sender As Object, e As EventArgs)
        For Each item As GridDataItem In RadGrid1.MasterTableView.Items
            If item.HasChildItems Then
                item.BackColor = System.Drawing.Color.Blue
            End If
        Next
    End Sub

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. armando
    armando avatar
    4 posts
    Member since:
    Sep 2008

    Posted 15 Sep 2011 Link to this post

    Thanks Shinu, but No working, I don't have data in the detail table, even the row color changes.
    let me show you my html code,
    Some labels are in Spanish.
     <telerik:RadGrid ID="RadGridPEDG" runat="server" DataSourceID="ZetaDataSourcePEDG"
                                    GridLines="None" AllowAutomaticDeletes="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True"
                                    AllowPaging="True" AutoGenerateColumns="False" AllowSorting="True" ShowStatusBar="True"
                                    OnItemCommand="RadGridPEDG_ItemCommand" OnItemUpdated="RadGridPEDG_ItemUpdated"
                                    OnItemInserted="RadGridPEDG_ItemInserted"
                                    Skin="Office2007">
                                    <MasterTableView Name="Referencias" DataKeyNames="idGastosAgencia,Periodo" Width="100%"
                                        CommandItemDisplay="Top" DataSourceID="ZetaDataSourcePEDG" HorizontalAlign="NotSet"
                                        AutoGenerateColumns="False" NoDetailRecordsText="No registros por mostrar" NoMasterRecordsText="No registros por mostrar"
                                        PageSize="10" retrievealldatafields="False">
                                        <DetailTables>
                                            <telerik:GridTableView Name="Archivos" DataKeyNames="idGastosAgenciaDet" DataSourceID="ZetaDataSourceArchivos"
                                                Width="100%" runat="server" CommandItemDisplay="Top" PageSize="5">
                                                <ParentTableRelation>
                                                    <telerik:GridRelationFields DetailKeyField="idGastosAgencia" MasterKeyField="idGastosAgencia" />
                                                </ParentTableRelation>
                                                <CommandItemSettings AddNewRecordText="Agregar Registro" RefreshText="Refrescar" />
                                                <commanditemsettings addnewrecordtext="Agregar Registro"
                                                    refreshtext="Refrescar" />
                                                <Columns>
                                                    <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn">
                                                    </telerik:GridEditCommandColumn>
                                                    <telerik:GridBoundColumn SortExpression="idGastosAgenciaDet" HeaderText="Archivo ID"
                                                        HeaderButtonType="TextButton" DataField="idGastosAgenciaDet" UniqueName="idGastosAgenciaDet"
                                                        Visible="false" ReadOnly="true">
                                                    </telerik:GridBoundColumn>
                                                    <telerik:GridBoundColumn SortExpression="nombrearchivo" HeaderText="Nombre" HeaderButtonType="TextButton"
                                                        DataField="nombrearchivo" UniqueName="nombrearchivo" ReadOnly="true">
                                                    </telerik:GridBoundColumn>
                                                    <telerik:GridTemplateColumn DataField="descripcion" HeaderButtonType="TextButton"
                                                        HeaderText="Descripción" SortExpression="descripcion" UniqueName="descripcion">
                                                        <EditItemTemplate>
                                                            <asp:TextBox ID="descripcionTextBox" runat="server" Text='<%# Bind("descripcion") %>'></asp:TextBox>
                                                            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="descripcionTextBox"
                                                                ErrorMessage="Se requiere capturar el campo Descripción para grabar el registro."
                                                                runat="server">
                                                            </asp:RequiredFieldValidator>
                                                        </EditItemTemplate>
                                                        <ItemTemplate>
                                                            <asp:Label ID="descripcionLabel" runat="server" Text='<%# Eval("descripcion") %>'></asp:Label>
                                                        </ItemTemplate>
                                                    </telerik:GridTemplateColumn>
                                                    <telerik:GridTemplateColumn DataField="archivo" HeaderText="Archivo" SortExpression="archivo"
                                                        UniqueName="fileupload">
                                                        <EditItemTemplate>
                                                            <%-- <asp:FileUpload ID="FileUploadArchivo" runat="server" />--%>
                                                            <telerik:RadUpload runat="server" ID="FileUploadArchivo" MaxFileInputsCount="1" InitialFileInputsCount="1"
                                                                OverwriteExistingFiles="True" Language="ES-es" AllowedFileExtensions=".jpg,.jpeg,.pdf,.xls,*.xlsx,.doc,.docx,.xml,.txt">
                                                                <Localization Add="Agregar" Clear="Limpiar" Delete="Borrar" Remove="Remorver" Select="Seleccionar" />
                                                            </telerik:RadUpload>
                                                        </EditItemTemplate>
                                                        <ItemTemplate>
                                                            <asp:HyperLink ID="HyperLinkArchivo" runat="server" NavigateUrl='<%# Eval("idGastosAgenciaDet") %>'
                                                                Target="_blank">Ver Archivo</asp:HyperLink>
                                                        </ItemTemplate>
                                                    </telerik:GridTemplateColumn>
                                                    <telerik:GridButtonColumn ConfirmText="¿Esta seguro que desea borrar este archivo?"
                                                        ConfirmDialogType="RadWindow" ConfirmTitle="Delete" ButtonType="ImageButton"
                                                        CommandName="Delete" Text="Delete" UniqueName="DeleteColumn">
                                                        <ItemStyle HorizontalAlign="Center" />
                                                    </telerik:GridButtonColumn>
                                                </Columns>
                                                <EditFormSettings ColumnNumber="2" CaptionDataField="nombrearchivo" CaptionFormatString="Editando Archivo {0}">
                                                    <EditColumn ButtonType="ImageButton" CancelText="Cancelar" EditText="Editar" InsertText="Agregar"
                                                        UniqueName="EditCommandColumn1" UpdateText="Actualizar">
                                                    </EditColumn>
                                                    <FormTableStyle BackColor="White" CellPadding="2" CellSpacing="0" Height="110px" />
                                                    <FormMainTableStyle GridLines="None" CellSpacing="0" CellPadding="3" BackColor="White"
                                                        Width="100%" />
                                                    <FormTableItemStyle Wrap="False" />
                                                    <formtablestyle backcolor="White" cellpadding="2" cellspacing="0"
                                                        height="110px" />
                                                    <formmaintablestyle backcolor="White" cellpadding="3" cellspacing="0"
                                                        width="100%" />
                                                    <formtableitemstyle wrap="False" />
                                                    <FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle>
                                                    <FormTableButtonRowStyle HorizontalAlign="Right"></FormTableButtonRowStyle>
                                                </EditFormSettings>
                                            </telerik:GridTableView>
                                        </DetailTables>
                                        <CommandItemSettings AddNewRecordText="Agregar Documento" RefreshText="Refrescar" />
                                        <commanditemsettings addnewrecordtext="Agregar Documento"
                                            refreshtext="Refrescar" />
                                        <ExpandCollapseColumn Visible="True">
                                        </ExpandCollapseColumn>
                                        <Columns>
                                            <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumnReferencias">
                                            </telerik:GridEditCommandColumn>
                                            <telerik:GridTemplateColumn DataField="Folio" HeaderText="Folio" SortExpression="Folio"
                                                UniqueName="Folio" EditFormColumnIndex="0">
                                                <EditItemTemplate>
                                                    <asp:TextBox Enabled="true" ID="txtFolio" runat="server" Text='<%# Bind("Folio") %>'></asp:TextBox>
                                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="txtFolio"
                                                        ErrorMessage="Campo requerido." runat="server">
                                                    </asp:RequiredFieldValidator>
                                                </EditItemTemplate>
                                                <ItemTemplate>
                                                    <asp:Label ID="lblFolio" runat="server" Text='<%# Bind("Folio") %>'></asp:Label>
                                                </ItemTemplate>
                                            </telerik:GridTemplateColumn>
                                            <telerik:GridTemplateColumn DataField="Periodo" HeaderText="Periodo" SortExpression="Periodo"
                                                UniqueName="Periodo" EditFormColumnIndex="1">
                                                <EditItemTemplate>
                                                    <telerik:RadMaskedTextBox ID="txtPeriodo" Text='<%# Bind("Periodo") %>' runat="server"
                                                        Mask="##/####" EmptyMessage="MM/yyyy">
                                                    </telerik:RadMaskedTextBox>
                                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" ControlToValidate="txtPeriodo"
                                                        ErrorMessage="Campo requerido." runat="server">
                                                    </asp:RequiredFieldValidator>
                                                </EditItemTemplate>
                                                <ItemTemplate>
                                                    <asp:Label ID="lblPeriodo" runat="server" Text='<%# Bind("Periodo") %>'></asp:Label>
                                                </ItemTemplate>
                                            </telerik:GridTemplateColumn>
                                            <telerik:GridDropDownColumn AllowFiltering="false" AutoPostBackOnFilter="true" DataField="idProveedor"
                                                DataSourceID="ZetaDataSourceProv" DropDownControlType="RadComboBox" EditFormColumnIndex="0"
                                                FilterControlWidth="40px" FooterText="DropDown footer" HeaderText="Proveedor"
                                                ListTextField="nombreProveedor" ListValueField="provID" ShowFilterIcon="false"
                                                SortExpression="nombre" UniqueName="GridDropDownColumn">
                                            </telerik:GridDropDownColumn>
                                            <telerik:GridTemplateColumn DataField="idCompania" HeaderText="Compania" SortExpression="idCompania"
                                                UniqueName="idCompania" EditFormColumnIndex="1" Display="false" Visible="false">
                                                <EditItemTemplate>
                                                    <asp:TextBox ID="txtCompania" Text='<%# Bind("idCompania") %>' runat="server" Enabled="false">
                                                    </asp:TextBox>
                                                </EditItemTemplate>
                                                <ItemTemplate>
                                                    <asp:Label ID="lblCompania" runat="server" Text='<%# Bind("idCompania") %>'></asp:Label>
                                                </ItemTemplate>
                                            </telerik:GridTemplateColumn>
                                            <%--<telerik:GridDropDownColumn DataField="clienteID" UniqueName="clienteID" HeaderText="Cliente"
                                                DataSourceID="ZetaDataSourceClientes" ListTextField="nombrecliente" ListValueField="clienteID"
                                                EditFormColumnIndex="1">
                                            </telerik:GridDropDownColumn>--%>
                                            <telerik:GridButtonColumn ConfirmText="¿Esta seguro que desea borrar esta Documento?"
                                                ConfirmDialogType="RadWindow" ConfirmTitle="Delete" ButtonType="ImageButton"
                                                CommandName="Delete" Text="Delete" UniqueName="DeleteColumnReferencias">
                                                <ItemStyle HorizontalAlign="Center" />
                                            </telerik:GridButtonColumn>
                                        </Columns>
                                        <EditFormSettings ColumnNumber="2" CaptionDataField="Folio" CaptionFormatString="Editando Folio {0}">
                                            <EditColumn ButtonType="ImageButton" CancelText="Cancelar" EditText="Editar" InsertText="Agregar"
                                                UniqueName="EditCommandColumn1" UpdateText="Actualizar">
                                            </EditColumn>
                                            <FormTableStyle BackColor="White" CellPadding="2" CellSpacing="0" Height="110px" />
                                            <FormMainTableStyle GridLines="None" CellSpacing="0" CellPadding="3" BackColor="White"
                                                Width="100%" />
                                            <FormTableItemStyle Wrap="False" />
                                            <formtablestyle backcolor="White" cellpadding="2" cellspacing="0"
                                                height="110px" />
                                            <formmaintablestyle backcolor="White" cellpadding="3" cellspacing="0"
                                                width="100%" />
                                            <formtableitemstyle wrap="False" />
                                            <FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle>
                                            <FormTableButtonRowStyle HorizontalAlign="Right"></FormTableButtonRowStyle>
                                        </EditFormSettings>
                                    </MasterTableView>
                                </telerik:RadGrid>
  5. Andrey
    Admin
    Andrey avatar
    836 posts

    Posted 20 Sep 2011 Link to this post

    Hi Armando,

    I would suggest you using another approach to hide the expand/collapse button if there is no information in the corresponding detail table. The same code successfully could be used to change the color of the item which has no additional information in them as well. You could review the following help topic, to see how this could be achieved:
    http://www.telerik.com/help/aspnet-ajax/grid-hide-expand-collapse-images-when-no-records.html

    Additionally, I am attaching a sample project to show a working example of the code.

    Greetings,
    Andrey
    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