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

Details table expand causes Main table color styling to disappear

2 Answers 178 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 01 Apr 2015, 04:10 PM
I have a RadGrid with one Details table.  I have code-behind (ItemDataBound) that sets column colors based on data from the database.  Works great.

When expanding a Details table in any one row, the color styling in the Main table disappears.

Please see attached for a visual example.


--- Markup:
<%@ Page Title="Home Page" Language="vb" MasterPageFile="~/Site.Master" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="NPI2._Default" EnableEventValidation="true" %>
<%@ MasterType virtualpath="~/Site.Master" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
    <title>NPI</title>
    <script src="~/Scripts/tooltip.js" type="text/javascript"></script>
    <link href="Styles/NPI2.css" rel="stylesheet" type="text/css" />
    <link href="Styles/LogicPD.css" rel="stylesheet" type="text/css" />
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <asp:Label ID="lbl_Error" runat="server" Text="" Font-Size="11px"></asp:Label>
    <asp:HiddenField runat="server" ID="hid_custKey" />

    <div style="display:block; width:100%; height:auto;">
        <table width="100%" border="0" style="margin-bottom:20px;">
            <tr>
                <td class="npi_toptd1">
                    <div style="display:inline; float:left;">
                        View&nbsp;Archived:&nbsp;&nbsp;
                        <asp:CheckBox runat="server" ID="cbx_Archive" AutoPostBack="true" />
                    </div>
                    <asp:HiddenField runat="server" ID="hid_ArchCBox" Value="0" /></td>
                <td class="npi_toptd1">
                    View&nbsp;By&nbsp;Customer:&nbsp;&nbsp;
                    <telerik:RadDropDownList ID="RadDropDownList_Customers" runat="server" DataValueField="CustomerKey" DataTextField="CustomerName" AutoPostBack="true">
                    </telerik:RadDropDownList>
                </td>
                <td class="npi_toptd2">
                    <asp:Button runat="server" ID="btnNewProduct" Text="Add New Product" Enabled="false" />
                </td>
                <td class="npi_toptd2">
                    <input runat="server" type="button" id="btnNewCustomerRedirect" value="Add New Customer" display="false" onclick="redirCustomer('AddCustomer.aspx');" />
                </td>
            </tr>
        </table>


        
        <div style="float:left; height:90%; width:100%; overflow:auto;">

            <telerik:RadGrid ID="RadGrid_Main" runat="server"
                DataSourceID="Sql_Data_MainTable"
                AllowMultiRowSelection="false"
                AllowPaging="True"
                AlternatingItemStyle-BackColor="ControlLight"
                AutoGenerateColumns="False"
                AutoGenerateDeleteColumn="True"
                AutoGenerateEditColumn="True"
                CellSpacing="0"
                GridLines="None"
                GroupPanelPosition="Top"
                Height="600px"
                PageSize="500">
                <ClientSettings EnablePostBackOnRowClick="false" AllowDragToGroup="False" AllowGroupExpandCollapse="True">
                    <Scrolling AllowScroll="False" UseStaticHeaders="True" />
                    <Selecting AllowRowSelect="false" />
                </ClientSettings>
                <FilterMenu EnableImageSprites="False"></FilterMenu>
                <HeaderStyle Font-Bold="True" />
                <PagerStyle PageSizeControlType="RadComboBox"></PagerStyle>
                <MasterTableView
                    CommandItemDisplay="Top"
                    DataKeyNames="ProductKey"
                    DataSourceID="Sql_Data_MainTable"
                    EditMode="EditForms"
                    Name="NPI_MasterTable">
                    <EditFormSettings>
                        <EditColumn ButtonType="PushButton"></EditColumn>
                    </EditFormSettings>
                    <ExpandCollapseColumn Visible="True" HeaderStyle-Width="20px"></ExpandCollapseColumn>
                    <CommandItemSettings ShowAddNewRecordButton="true" AddNewRecordText="Add New Item"></CommandItemSettings>
                    <RowIndicatorColumn Visible="True" HeaderStyle-Width="20px"></RowIndicatorColumn>
                    <PagerStyle PageSizeControlType="RadComboBox"></PagerStyle>
                    <Columns>
                        <telerik:GridNumericColumn DataField="ProductKey" DecimalDigits="5" Display="False" HeaderText="ProductKey" UniqueName="ProductKey" ReadOnly="true"></telerik:GridNumericColumn>

                        <telerik:GridTemplateColumn HeaderText="Assembly Part Number" UniqueName="TemplateColumn_ItemID">
                            <HeaderStyle Width="150" Wrap="false" Font-Size="10px" />
                            <ItemStyle Font-Size="11px" />
                            <ItemTemplate>
                                <asp:Label ID="lbl_ItemID" runat="server" Text='<%# Eval("ItemID")%>' />
                                <br />
                                <asp:CheckBox id="cbx_PW" runat="server" Checked='<%# Eval("PacketWaiting") %>' Enabled="false"></asp:CheckBox>&nbsp;PW
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:Textbox ID="txt_ItemID" runat="server" Text='<%# Bind("ItemID")%>' ReadOnly="false" />
                                <br />
                                <asp:CheckBox id="cbx_PW" runat="server" Checked='<%# Bind("PacketWaiting") %>' Enabled="true"></asp:CheckBox>&nbsp;PW
                                <br />
                            </EditItemTemplate>
                            <InsertItemTemplate>
                                <asp:Textbox ID="txt_ItemID" runat="server" Text='' ReadOnly="false" />
                                <asp:RequiredFieldValidator ID="req1" runat="server" ErrorMessage="* Required" ControlToValidate="txt_ItemID" CssClass="Error tdRed"></asp:RequiredFieldValidator>
                                <br />
                                <asp:CheckBox id="cbx_PW" runat="server" Checked='false' Enabled="true"></asp:CheckBox>&nbsp;PW
                                <br />
                            </InsertItemTemplate>
                        </telerik:GridTemplateColumn>

                        <telerik:GridBoundColumn DataField="AssemblyRev" HeaderText="Assy Revision" UniqueName="AssyRev">
                            <HeaderStyle Width="50" Font-Size="10px" />
                            <ItemStyle Font-Size="11px" />
                            <ColumnValidationSettings EnableRequiredFieldValidation="true">
                                <RequiredFieldValidator ErrorMessage="&nbsp;* Required" CssClass="Error tdRed"></RequiredFieldValidator>
                            </ColumnValidationSettings>
                        </telerik:GridBoundColumn>

                        <telerik:GridDropDownColumn DataField="CustomerKey" DataSourceID="Sql_Data_Customers" HeaderText="Customer" ListTextField="CustomerName" ListValueField="CustomerKey" UniqueName="ddCustomer">
                            <HeaderStyle Width="130" Font-Size="10px" />
                            <ItemStyle Font-Size="11px" />
                            <ColumnValidationSettings EnableRequiredFieldValidation="true">
                                <RequiredFieldValidator ErrorMessage="&nbsp;* Required" CssClass="Error tdRed"></RequiredFieldValidator>
                            </ColumnValidationSettings>
                        </telerik:GridDropDownColumn>

                        
                        <telerik:GridTemplateColumn HeaderText="Expected<br />Start Date" UniqueName="StartDate">
                            <HeaderStyle Width="60" Font-Size="10px" />
                            <ItemStyle Font-Size="11px" />
                            <ItemTemplate>
                                <asp:Label runat="server" ID="lbl_StartDate" Text='<%# Eval("StartDate2")%>' />
                            </ItemTemplate>
                            <EditItemTemplate>
                                <telerik:RadDatePicker ID="dateP_StartDate" runat="server" SelectedDate='<%# CType(Eval("StartDate2"), Date)%>'></telerik:RadDatePicker>
                            </EditItemTemplate>
                            <InsertItemTemplate>
                                <telerik:RadDatePicker ID="dateP_StartDate" runat="server"></telerik:RadDatePicker>
                                <asp:RequiredFieldValidator ID="req2" runat="server" ErrorMessage="* Required" ControlToValidate="dateP_StartDate" CssClass="Error"></asp:RequiredFieldValidator>
                            </InsertItemTemplate>
                        </telerik:GridTemplateColumn>
                        
                        <telerik:GridDropDownColumn DataField="Status" DataSourceID="Sql_Data_Types" HeaderText="Type" ListTextField="Type" ListValueField="TypeKey" UniqueName="Type">
                            <HeaderStyle Width="110" HorizontalAlign="Center" Font-Size="10px" />
                            <ItemStyle Font-Size="11px" />
                            <ColumnValidationSettings EnableRequiredFieldValidation="true">
                                <RequiredFieldValidator ErrorMessage="&nbsp;* Required" CssClass="Error tdRed"></RequiredFieldValidator>
                            </ColumnValidationSettings>
                        </telerik:GridDropDownColumn>
                        
                        <telerik:GridTemplateColumn HeaderText="Expected<br />Ship Date" UniqueName="ShipDate">
                            <HeaderStyle Width="60" Font-Size="10px" />
                            <ItemStyle Font-Size="11px" />
                            <ItemTemplate>
                                <asp:Label runat="server" ID="lbl_ShipDate" Text='<%# Eval("ShipDate")%>' />
                            </ItemTemplate>
                            <EditItemTemplate>
                                <telerik:RadDatePicker ID="dateP_ShipDate" runat="server" SelectedDate='<%# CType(Eval("ShipDate"), Date)%>'></telerik:RadDatePicker>
                            </EditItemTemplate>
                            <InsertItemTemplate>
                                <telerik:RadDatePicker ID="dateP_ShipDate" runat="server"></telerik:RadDatePicker>
                                <asp:RequiredFieldValidator ID="req3" runat="server" ErrorMessage="* Required" ControlToValidate="dateP_ShipDate" CssClass="Error"></asp:RequiredFieldValidator>
                            </InsertItemTemplate>
                        </telerik:GridTemplateColumn>
                        
                        <telerik:GridBoundColumn DataField="ECONum" HeaderText="ECO<br />Number" UniqueName="ECONumber">
                            <HeaderStyle Width="80" Font-Size="10px" />
                            <ItemStyle Font-Size="11px" />
                        </telerik:GridBoundColumn>

                        <telerik:GridBoundColumn DataField="PO_JobNumber" HeaderText="PO/<br />Job Number" UniqueName="POJob">
                            <HeaderStyle Width="80" Font-Size="10px" />
                            <ItemStyle Font-Size="11px" />
                        </telerik:GridBoundColumn>

                        <telerik:GridDropDownColumn DataField="CustomerFocusEng" DataSourceID="Sql_Data_CFEng" HeaderText="Customer Focus<br />Engineer" ListTextField="EngineerName" ListValueField="CustomerFocusEngKey" UniqueName="ddCFEng">
                            <HeaderStyle Width="100" Font-Size="10px" />
                            <ItemStyle Font-Size="11px" />
                            <ColumnValidationSettings EnableRequiredFieldValidation="true">
                                <RequiredFieldValidator ErrorMessage="&nbsp;* Required" CssClass="Error tdRed"></RequiredFieldValidator>
                            </ColumnValidationSettings>
                        </telerik:GridDropDownColumn>

                        <telerik:GridBoundColumn DataField="CommentsFull" HeaderText="Comments" UniqueName="CommentsFull" Display="false"></telerik:GridBoundColumn>

                        <telerik:GridBoundColumn DataField="Comments" HeaderText="Comments..." UniqueName="Comments" ReadOnly="true">
                            <HeaderStyle Width="150" Font-Size="10px" />
                            <ItemStyle Font-Size="11px" />
                        </telerik:GridBoundColumn>

                        <telerik:GridDropDownColumn DataField="PasteStencils" DataSourceID="Sql_Data_Stati" ListTextField="Status" ListValueField="StatusKey" HeaderText="Stencil" UniqueName="PasteStencils">
                            <HeaderStyle Width="5" HorizontalAlign="Center" Font-Size="9px" />
                            <ItemStyle Font-Size="2px" />
                            <ColumnValidationSettings EnableRequiredFieldValidation="true">
                                <RequiredFieldValidator ErrorMessage="&nbsp;* Required" CssClass="Error tdRed"></RequiredFieldValidator>
                            </ColumnValidationSettings>
                        </telerik:GridDropDownColumn>

                        <telerik:GridDropDownColumn DataField="SideSMT" DataSourceID="Sql_Data_Stati" ListTextField="Status" ListValueField="StatusKey" HeaderText="SMT" UniqueName="SMT">
                            <HeaderStyle Width="5" HorizontalAlign="Center" Font-Size="10px" /> 
                            <ItemStyle Font-Size="2px" />                           
                            <ColumnValidationSettings EnableRequiredFieldValidation="true">
                                <RequiredFieldValidator ErrorMessage="&nbsp;* Required" CssClass="Error tdRed"></RequiredFieldValidator>
                            </ColumnValidationSettings>
                        </telerik:GridDropDownColumn>

                        <telerik:GridDropDownColumn DataField="Approval" DataSourceID="Sql_Data_Approval" HeaderText="Approval" ListTextField="ApprovalStatus" ListValueField="ApprovalKey" UniqueName="ddApproval">
                            <HeaderStyle Width="65" Font-Size="10px" />
                            <ItemStyle Font-Size="11px" />
                            <ColumnValidationSettings EnableRequiredFieldValidation="true">
                                <RequiredFieldValidator ErrorMessage="&nbsp;* Required" CssClass="Error tdRed"></RequiredFieldValidator>
                            </ColumnValidationSettings>
                        </telerik:GridDropDownColumn>

                    </Columns>

                    <DetailTables>
                        <telerik:GridTableView Name="NPI_DetailsTable_Admin" runat="server"
                            DataSourceID="Sql_Data_DetailTable"
                            AllowAutomaticInserts="False"
                            AllowPaging="False"
                            AlternatingItemStyle-BackColor="#F7EED7"
                            AutoGenerateColumns="false"
                            CommandItemDisplay="Top"
                            DataKeyNames="ProductKey"
                            EditMode="PopUp"
                            EnableHeaderContextMenu="True"
                            GroupsDefaultExpanded="True" 
                            GroupLoadMode="Client"
                            HeaderStyle-ForeColor="#873F00"
                            HeaderStyle-Font-Bold="true"
                            ItemStyle-BackColor="#FAE5B4"
                            Width="100%">
                            <EditFormSettings>
                                <EditColumn FilterControlAltText="Filter EditCommandColumn column" ButtonType="PushButton"></EditColumn>
                            </EditFormSettings>
                            <ParentTableRelation>
                                <telerik:GridRelationFields DetailKeyField="ProductKey" MasterKeyField="ProductKey" />
                            </ParentTableRelation>
                            <CommandItemSettings ShowAddNewRecordButton="false" ShowRefreshButton="true" />
                            <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column" Visible="True" HeaderStyle-Width="20px" />
                            <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" Visible="True" HeaderStyle-Width="20px" />
                            <Columns>
                                <telerik:GridNumericColumn DataField="ProductKey" DecimalDigits="0" Display="False" HeaderText="ProductKey" UniqueName="ProductKey" ReadOnly="true"></telerik:GridNumericColumn>
                                <telerik:GridNumericColumn DataField="CategoryKey" DecimalDigits="0" Display="False" HeaderText="CategoryKey" UniqueName="CategoryKey" ReadOnly="true"></telerik:GridNumericColumn>
                                <telerik:GridBoundColumn DataField="Category" HeaderText="Category" UniqueName="Category" ReadOnly="true"></telerik:GridBoundColumn>
                                
                                <telerik:GridBoundColumn DataField="RoHS_Color" HeaderText="RoHS_Color" UniqueName="RoHS_Color" ReadOnly="true" Display="false"></telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="RoHS_opt" HeaderText="RoHS_opt" UniqueName="RoHS_opt" ReadOnly="true" Display="false"></telerik:GridBoundColumn>
                                <telerik:GridTemplateColumn HeaderText="RoHS<br />Requirements" UniqueName="RoHS">
                                    <HeaderStyle Width="60" Font-Size="10px" />
                                    <ItemStyle Font-Size="11px" />
                                    <ItemTemplate>
                                        <asp:Label runat="server" ID="lbl_User" Text='<%# Eval("RoHS_User")%>' /><br />
                                        <asp:Label runat="server" ID="lbl_Option" Text='<%# Eval("RoHS_opt")%>' />
                                        <asp:HiddenField runat="server" ID="hid_Color_RoHS" Value='<%# Eval("RoHS_Color")%>' />
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                            </Columns>
                        </telerik:GridTableView>
                    </DetailTables>
                </MasterTableView>
            </telerik:RadGrid>


            <%'Data Sources %>
            <asp:SqlDataSource ID="Sql_Data_MainTable" runat="server" SelectCommand="npi.GetNPIData_MainTable" SelectCommandType="StoredProcedure">
                <SelectParameters>
                    <asp:ControlParameter ControlID="cbx_Archive" DefaultValue="0" Name="seeArchived" PropertyName="Checked" Type="Boolean" />
                    <asp:ControlParameter ControlID="RadDropDownList_Customers" DefaultValue="1" Name="custKey" PropertyName="SelectedValue" Type="Int32" />
                </SelectParameters>
            </asp:SqlDataSource>
            <asp:SqlDataSource ID="Sql_Data_Customers" runat="server" SelectCommand="npi.GetCustomersAll" SelectCommandType="StoredProcedure" ProviderName="System.Data.SqlClient"></asp:SqlDataSource>
            <asp:SqlDataSource ID="Sql_Data_Types" runat="server" SelectCommand="npi.GetType" SelectCommandType="StoredProcedure" ProviderName="System.Data.SqlClient"></asp:SqlDataSource>
            <asp:SqlDataSource ID="Sql_Data_CFEng" runat="server" SelectCommand="npi.GetCustomerFocusEng" SelectCommandType="StoredProcedure" ProviderName="System.Data.SqlClient"></asp:SqlDataSource>
            <asp:SqlDataSource ID="Sql_Data_Approval" runat="server" SelectCommand="npi.GetApproval" SelectCommandType="StoredProcedure" ProviderName="System.Data.SqlClient"></asp:SqlDataSource>
            <asp:SqlDataSource ID="Sql_Data_Stati" runat="server" SelectCommand="npi.GetNPIStati" SelectCommandType="StoredProcedure" ProviderName="System.Data.SqlClient"></asp:SqlDataSource>
            
            <asp:SqlDataSource ID="Sql_Data_DetailTable" runat="server" SelectCommand="npi.GetNPIData_DetailTable" SelectCommandType="StoredProcedure" ProviderName="System.Data.SqlClient">
                <SelectParameters>
                    <asp:ControlParameter ControlID="RadGrid_Main" Name="ProductKey" PropertyName="SelectedValue" Type="Int64" />
                </SelectParameters>
            </asp:SqlDataSource>
        </div>
        <br />
        <div style="float:right">
            <table style="width:320px; float:right; border:1px solid black; font-size:x-small; margin-top:20px;">
                <tr>
                    <td style="background-color: #88DD88; text-align:center;">Complete or Not Required</td>
                    <td style="background-color: #FFFFAA; text-align:center;">In Process</td>
                    <td style="background-color: #FFAAAA; text-align:center;">Hold/Not Started</td>
                </tr>
            </table>
        </div>


    </div>
</asp:Content>


--- Code-behind:


Imports System.Environment
Imports System.Web.UI.WebControls.LoginName
Imports System
Imports System.Collections
Imports System.Collections.Generic
Imports System.Data
Imports System.Data.SqlClient
Imports System.Text
Imports System.Text.RegularExpressions
Imports NPI2.DBAccess
Imports Telerik.Web.UI
Imports ACME_Utilities
Imports Outlook = Microsoft.Office.Interop.Outlook
Imports System.DirectoryServices

Public Class _Default
    Inherits System.Web.UI.Page

#Region "variables"
    Dim connStr As String
    Dim Environ As String
    Dim DAccess As New DBAccess
    Dim Comments_ProductID As String    'for use with Comments (productID)
    Dim prodID As String
    Dim colID As String
    Dim newProductInd As String
    Dim headerDS As New DataSet
    Dim modal3DS As New DataSet
    Dim selectedColor As String
    Dim changeInd As Boolean
    Dim includeArchive As Boolean
    Public archInd As String
    Dim sort As String
    Dim order As String
    Dim order2 As String
    Dim table2id As Int64
    Public commentKey As Int32
    Public tblb As String
    Public CustomerKey As Int32
    Public category As String
    Public userName As String
    Public RowProductKey As Int64

    Dim UpdateIndicator As Boolean
    Dim strReturnValue As String
#End Region

    Private Sub Page_Init(sender As Object, e As System.EventArgs) Handles Me.Init
        Try
            If InStr(Request.Url.ToString(), "appserver") > 0 Then Environ = "prod" Else Environ = "dev"
            connStr = System.Configuration.ConfigurationManager.ConnectionStrings(Environ).ConnectionString
            Sql_Data_Approval.ConnectionString = connStr
            Sql_Data_CFEng.ConnectionString = connStr
            Sql_Data_Customers.ConnectionString = connStr
            Sql_Data_MainTable.ConnectionString = connStr
            Sql_Data_Types.ConnectionString = connStr
            Sql_Data_DetailTable.ConnectionString = connStr
        Catch ex As Exception
            ErrorLog_Write("NPI - Default.aspx", ex.Message, "PageInit")
        End Try
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            Sql_Data_MainTable.ConnectionString = connStr
            Sql_Data_Customers.ConnectionString = connStr
            Sql_Data_Types.ConnectionString = connStr
            Sql_Data_CFEng.ConnectionString = connStr
            Sql_Data_Approval.ConnectionString = connStr
            Sql_Data_Stati.ConnectionString = connStr

            lbl_Error.Text = ""
            lbl_Error.Visible = False
            lbl_Error.ForeColor = Drawing.Color.Black
            lbl_Error.BackColor = Drawing.Color.Transparent

            hid_custKey.Value = RadDropDownList_Customers.SelectedValue
            hid_ArchCBox.Value = IIf(cbx_Archive.Checked, 1, 0)

            userName = Master.LoginName()
            If userName = "" Then userName = Context.User.Identity.Name.Replace("ACME\", "")
            If userName = "" Then userName = HttpContext.Current.Request.LogonUserIdentity.Name.ToString.Split("\"c)(1)
            If userName = "" Then userName = "uknown"

            GetCustomersForDropDownList()

            If IsPostBack Then
                'RadGrid_Main.Rebind()
                'RadGrid_Main.MasterTableView.ClearEditItems()   'Closes the Edit window, if it is open
            End If

        Catch ex As Exception
            ErrorLog_Write("NPI - Default.aspx", ex.Message, "PageLoad")
        End Try
    End Sub

    
    Protected Sub GetCustomersForDropDownList()
        Try
            Dim dsC As New DataSet
            dsC = DBAccess.GetSPData("npi.Customers_Get_Active", "PopulateCustomerDropDown", connStr)
            RadDropDownList_Customers.DataSource = dsC.Tables(0)
            RadDropDownList_Customers.DataBind()

            'Modal:
            'RadDropDownList_Customers.DataSource = dsC.Tables(0)
            'RadDropDownList_Customers.DataBind()
        Catch ex As Exception
            ErrorLog_Write("NPI - Default.aspx", ex.Message, "RadGrid_MainTable_ItemDataBound")
        End Try
    End Sub



#Region "RadGrid_Main construction"
    Private Sub RadGrid_Main_ItemCommand(sender As Object, e As GridCommandEventArgs) Handles RadGrid_Main.ItemCommand
        If e.CommandName = RadGrid.InitInsertCommandName Then
            e.Canceled = True
            'Prepare an IDictionary with the predefined values
            Dim newValues As New System.Collections.Specialized.ListDictionary
            'set initial checked state for the checkbox on init insert  
            newValues("cbx_PW") = False
            'Insert the item and rebind  
            e.Item.OwnerTableView.InsertItem(newValues)
        End If
    End Sub

    Private Sub radGrid_Main_ItemCreated(sender As Object, e As GridItemEventArgs) Handles RadGrid_Main.ItemCreated
        Try
            If TypeOf e.Item Is GridDataItem Then
                Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
                Dim deleteBtn As LinkButton = DirectCast(item.FindControl("AutoGeneratedDeleteButton"), LinkButton)
                deleteBtn.Attributes.Add("onclick", "return confirm('Are you sure you want to delete this row?')")
            End If

            If (TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode) Then
                Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)

                Dim txBx As TextBox = CType(editedItem("CommentsFull").Controls.Item(0), TextBox)
                txBx.Width = 500
                txBx.Height = 75
                txBx.TextMode = TextBoxMode.MultiLine
            End If

            If TypeOf e.Item Is GridCommandItem Then
                Dim commandItem As GridCommandItem = CType(e.Item, GridCommandItem)
                commandItem.Width = 30
            End If

        Catch ex As Exception
            ErrorLog_Write("NPI - Default.aspx", ex.Message, "radGrid_Main_ItemCreated")
        End Try
    End Sub

    Private Sub RadGrid_Main_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid_Main.ItemDataBound
        If (TypeOf e.Item Is GridDataItem) Then
            Dim dataBoundItem As GridDataItem = CType(e.Item, GridDataItem)

            If e.Item.OwnerTableView.Name = "NPI_MasterTable" Then
                If dataBoundItem("Comments").Text = "..." Then
                    dataBoundItem("Comments").Text = ""
                    dataBoundItem("Comments").ToolTip = ""
                Else
                    dataBoundItem("Comments").ToolTip = dataBoundItem("CommentsFull").Text
                End If
'Coloration: Main table
                If dataBoundItem("Type").Text = "Box Build" Then
                    dataBoundItem("Type").BackColor = Drawing.Color.FromName("#ffaaaa")
                ElseIf dataBoundItem("Type").Text = "Kit" Then
                    dataBoundItem("Type").BackColor = Drawing.Color.FromName("#77aaff")
                ElseIf dataBoundItem("Type").Text = "New Assy" Then
                    dataBoundItem("Type").BackColor = Drawing.Color.FromName("#ffffaa")
                ElseIf dataBoundItem("Type").Text = "NwAssy/ExstngPCB" Then
                    dataBoundItem("Type").BackColor = Drawing.Color.FromName("#88dd88")
                ElseIf dataBoundItem("Type").Text = "ECO" Then
                    dataBoundItem("Type").BackColor = Drawing.Color.FromName("#C0C0C0")
                ElseIf dataBoundItem("Type").Text = "PMONPI" Then
                    dataBoundItem("Type").BackColor = Drawing.Color.FromName("#DBE7FF")
                ElseIf dataBoundItem("Type").Text = "ECO-New Pwb" Then
                    dataBoundItem("Type").BackColor = Drawing.Color.FromName("#FFE3AD")
                ElseIf dataBoundItem("Type").Text = "Machine Transfer" Then
                    dataBoundItem("Type").BackColor = Drawing.Color.FromName("#DBBC97")
                ElseIf dataBoundItem("Type").Text = "WC Transfer" Then
                    dataBoundItem("Type").BackColor = Drawing.Color.FromName("#C69DED")
                End If

                If dataBoundItem("PasteStencils").Text = "Hold/Not Started" Then
                    dataBoundItem("PasteStencils").ForeColor = Drawing.Color.FromName("#ffaaaa")
                    dataBoundItem("PasteStencils").BackColor = Drawing.Color.FromName("#ffaaaa")
                ElseIf dataBoundItem("PasteStencils").Text = "In Process" Then
                    dataBoundItem("PasteStencils").ForeColor = Drawing.Color.FromName("#ffffaa")
                    dataBoundItem("PasteStencils").BackColor = Drawing.Color.FromName("#ffffaa")
                Else
                    dataBoundItem("PasteStencils").ForeColor = Drawing.Color.FromName("#88dd88")
                    dataBoundItem("PasteStencils").BackColor = Drawing.Color.FromName("#88dd88")
                End If

                If dataBoundItem("SMT").Text = "Hold/Not Started" Then
                    dataBoundItem("SMT").ForeColor = Drawing.Color.FromName("#ffaaaa")
                    dataBoundItem("SMT").BackColor = Drawing.Color.FromName("#ffaaaa")
                ElseIf dataBoundItem("SMT").Text = "In Process" Then
                    dataBoundItem("SMT").ForeColor = Drawing.Color.FromName("#ffffaa")
                    dataBoundItem("SMT").BackColor = Drawing.Color.FromName("#ffffaa")
                Else
                    dataBoundItem("SMT").ForeColor = Drawing.Color.FromName("#88dd88")
                    dataBoundItem("SMT").BackColor = Drawing.Color.FromName("#88dd88")
                End If

                If dataBoundItem("ddCFEng").Text = "&nbsp;" Then dataBoundItem("ddCFEng").Text = "Select..."
            ElseIf e.Item.OwnerTableView.Name = "NPI_DetailsTable_Admin" Then
                Dim nestedTableView As GridTableView = CType(RadGrid_Main.MasterTableView.Items(0), GridDataItem).ChildItem.NestedTableViews(0) 'not used yet

'Coloration: details table
                If dataBoundItem("RoHS_Color").Text = "2" Then
                    dataBoundItem("RoHS").BackColor = Drawing.Color.FromName("#FFFFAA")
                ElseIf dataBoundItem("RoHS_Color").Text = "3" Then
                    dataBoundItem("RoHS").BackColor = Drawing.Color.FromName("#FFAAAA")
                Else
                    dataBoundItem("RoHS").BackColor = Drawing.Color.FromName("#88DD88")
                End If

                Dim _lbl_RoHS_opt As Label = CType(dataBoundItem("RoHS").FindControl("lbl_Option"), Label)
                If dataBoundItem("RoHS_opt").Text = "0" Then
                    _lbl_RoHS_opt.Text = "No"
                Else
                    _lbl_RoHS_opt.Text = "Yes"
                End If
            End If

        End If
    End Sub


#End Region



#Region "Command Events"
    'Insert into Main Table
    Private Sub RadGrid_Main_InsertCommand(sender As Object, e As GridCommandEventArgs) Handles RadGrid_Main.InsertCommand
        Try
            If e.Item.OwnerTableView.Name = "NPI_MasterTable" Then
                'Insert code
            End If
        Catch ex As Exception
            ErrorLog_Write("NPI - Default.aspx", ex.Message, "RadGrid_Main_InsertCommand")
        End Try
    End Sub

    'Update Main Table item
    Private Sub RadGrid_Main_UpdateCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid_Main.UpdateCommand
        Try
            If e.Item.OwnerTableView.Name = "NPI_MasterTable" Then
                'Update Code
            End If
        Catch ex As Exception
            ErrorLog_Write("NPI - Default.aspx", ex.Message, "RadGrid_Main_UpdateCommand")
        End Try
    End Sub

    'Delete from Main Table
    Private Sub RadGrid_Main_DeleteCommand(sender As Object, e As GridCommandEventArgs) Handles RadGrid_Main.DeleteCommand
        Try
            If e.Item.OwnerTableView.Name = "NPI_MasterTable" Then
                'Delete Code
            End If
        Catch ex As Exception
            ErrorLog_Write("NPI - Default.aspx", ex.Message, "RadGrid_Main_DeleteCommand")
        End Try
    End Sub
#End Region



#Region "Error Handling"
    'Write Errors to the database
    Public Sub ErrorLog_Write(ByVal page, ByVal exMessage, ByVal Err2)
        Try
            'Error handling
        Catch ex As Exception
            lbl_Error.Text = "There was an error writing to the Error Log.<br />The error was not saved.<br /><br />(Page: " + page + ")"
        End Try
    End Sub
#End Region
End Class






2 Answers, 1 is accepted

Sort by
0
Accepted
Kostadin
Telerik team
answered on 06 Apr 2015, 07:11 AM
Hello Chris,

The reason for that behavior is that the grid does call ItemDataBound event handler when expand/collapse command is fired and and in this case the applied styles are lost. A possible solution is to manually loop through all items on PreRender event handler and apply a styles to each item. For your convenience I prepared a small runnable sample and attached it to this thread.

Regards,
Kostadin
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Chris
Top achievements
Rank 1
answered on 06 Apr 2015, 04:28 PM

That did it, Kostadin.  I had forgotten about the ItemDatabound not firing for the main table when expanding a details table.  Your solution works perfectly.  Thank you very much!

- Chris

Tags
Grid
Asked by
Chris
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
Chris
Top achievements
Rank 1
Share this question
or