RadGrid Detail Table only expands for one row in mastertableview

7 posts, 0 answers
  1. Brad
    Brad avatar
    4 posts
    Member since:
    Sep 2015

    Posted 29 Sep 2015 Link to this post

    I have an autogenerated radgrid and detail table. I am resizeToFit() the columns in both the mastertableview, and the detailtable. (see javascript block). I am colorizing cell backcolors based upon the cell value.

     

    When a user clicks a row, or clicks the expand/collapse image, the PartnerID is then stored in the Session Data, to retrieve the respective data from the db. The PartnerID's in the parent table, match those in the DetailTable.

     

    Everything works as expected, however I am only able to expand one row when the page has finished loading. It does not matter which row it is. I can expand that row once, and then collapse that row once. After that I am unable to expand any other row in the parent table. Clicking on the other expand icons triggers a postback, but nothing is changed. I have tried expanding a row, and then attempting to expand a second row, but that does not work either.

     

    I have verified that the datasource is retrieving new data based on the session variable. I have tried using the selected value for RadGrid1 on my datasource, and that works fine. But the behavior is the same.

     

    The data to populate the parent table, looks like this. It comes from SqlDataSourcePartnerOverview

    |PartnerID|PartnerName|num_patients|avg_answer|Q1|Q2|Q3|

    |int|string|int|double|double|double|double|

     

    The data to populate the detail table, looks like this. It comes from SqlDataSourcePartnerQuestionDetails

    |PartnerID|QuestionNumber|Question|num_patients|num_responses|avg_answer|

    |int|int|string|int|int|double|

     
     I have a second radgrid that is populated based on the Session["PartnerID"], but that works fine, so I haven't included it's source.
     
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
                    <AjaxSettings>
                        <telerik:AjaxSetting AjaxControlID="RadGrid1">
                            <UpdatedControls>
                                <telerik:AjaxUpdatedControl ControlID="RadGrid1"></telerik:AjaxUpdatedControl>
                                <telerik:AjaxUpdatedControl ControlID="RadGrid2" LoadingPanelID="RadAjaxLoadingPanel1"></telerik:AjaxUpdatedControl>
                            </UpdatedControls>
                        </telerik:AjaxSetting>
                        <telerik:AjaxSetting AjaxControlID="RadGrid2">
                            <UpdatedControls>
                                <telerik:AjaxUpdatedControl ControlID="RadGrid2"></telerik:AjaxUpdatedControl>
                            </UpdatedControls>
                        </telerik:AjaxSetting>
                    </AjaxSettings>
                </telerik:RadAjaxManager>
                <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Metro" Transparency="75" />
                <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
                    <script type="text/javascript">
                        function gridCreated(sender, args) {
                            var columns = sender.get_masterTableView().get_columns();
                            for (var i = 0; i < columns.length; i++) {
                                columns[i].resizeToFit(false, true);
                            }
                        }
     
                        function detailCreated(sender, eventArgs) {
                            var detailTables = sender.get_detailTables();
                            //iterates over all detail tables in gridview
                            for (var i = 0; i < detailTables.length; i++) {
                                var detailColumns = detailTables[i].get_columns();
                                //iterates over each column in detail table
                                for (var j = 0; j < detailColumns.length; j++) {
                                    detailColumns[j].resizeToFit(false, true);
                                }
                            }
     
                        }
                    </script>
                </telerik:RadCodeBlock>
                <br />
                <br />
                <h3>Partner Overview:</h3>
                <div id="partnerGridDiv">
                    <telerik:RadGrid
                        runat="server"
                        ID="RadGrid1"
                        Skin="Metro"
                        BorderStyle="Solid"
                        AllowSorting="True"
                        DataSourceID="SqlDataSourcePartnerOverview"
                        OnItemCommand="RadGrid_ItemCommand"
                        AutoGenerateColumns="true"
                        OnColumnCreated="RadGrid_ColumnCreated"
                        OnItemDataBound="RadGrid_ItemDataBound"
                        EnableHeaderContextMenu="true"
                        ShowFooter="true"
                        ViewStateMode="Enabled"
                        MasterTableView-HierarchyLoadMode="ServerOnDemand">
                        <ClientSettings AllowKeyboardNavigation="true" EnablePostBackOnRowClick="true">
                            <Selecting AllowRowSelect="true"></Selecting>
                            <Resizing ResizeGridOnColumnResize="true" AllowColumnResize="true" AllowResizeToFit="True" />
                            <Scrolling AllowScroll="false" UseStaticHeaders="false" />
                            <ClientEvents OnGridCreated="gridCreated" OnTableCreated="detailCreated"/>
                        </ClientSettings>
                        <HeaderStyle BackColor="#42608D" ForeColor="White" HorizontalAlign="Left" />
                        <ItemStyle HorizontalAlign="Left" />
                        <MasterTableView TableLayout="fixed" NoMasterRecordsText="No records found" DataKeyNames="PartnerID" DataSourceID="SqlDataSourcePartnerOverview">
                            <DetailTables>
                                <telerik:GridTableView Width="75%" AutoGenerateColumns="true" Name="PartnerDetailTable" runat="server" DataSourceID="SqlDataSourcePartnerQuestionDetails" DataKeyNames="PartnerID"  ShowFooter="true">
                                    <ParentTableRelation>
                                        <telerik:GridRelationFields DetailKeyField="PartnerID" MasterKeyField="PartnerID" />
                                    </ParentTableRelation>
                                    <Columns>
                                        <%--<telerik:GridBoundColumn DataField="QuestionNumber" DataType="System.Int32" HeaderText="Question Number" SortExpression="QuestionNumber" UniqueName="QuestionNumber" HeaderStyle-Width="10%" />
                                        <telerik:GridBoundColumn DataField="Question" Aggregate="Count" HeaderText="Question" FooterStyle-HorizontalAlign="Left" SortExpression="PartnerName" UniqueName="PartnerName" />
                                        <telerik:GridBoundColumn DataField="num_patients" DataFormatString="{0:n0}" Aggregate="Sum" FooterAggregateFormatString="Total: {0:n0}" FooterStyle-HorizontalAlign="Left" HeaderStyle-Width="10%" DataType="System.Int32" HeaderText="# of Patients" ReadOnly="True" SortExpression="num_patients" UniqueName="num_patients" />
                                        <telerik:GridBoundColumn DataField="num_responses" DataFormatString="{0:n0}" Aggregate="Sum" FooterAggregateFormatString="Total: {0:n0}" FooterStyle-HorizontalAlign="Left" HeaderStyle-Width="10%" DataType="System.Int32" HeaderText="# of Responses" ReadOnly="True" SortExpression="num_responses" UniqueName="num_responses" />
                                        <telerik:GridBoundColumn DataField="avg_answer" DataFormatString="{0:P0}" DataType="System.Double" FilterControlAltText="Filter avg_answer column" HeaderText="Average Response" ReadOnly="True" SortExpression="avg_answer" UniqueName="avg_answer" />--%>
                                    </Columns>
                                </telerik:GridTableView>
                            </DetailTables>
                        </MasterTableView>
                    </telerik:RadGrid>
                </div>
     
    <asp:SqlDataSource ID="SqlDataSourcePartnerOverview" runat="server" ConnectionString="<%$ ConnectionStrings:mdpSupportServices %>" SelectCommand="rpt_SurveyData_Partner_Overview" SelectCommandType="StoredProcedure">
                <SelectParameters>
                    <asp:ControlParameter ControlID="RadDatePickerStartDate" PropertyName="SelectedDate" Name="startDate" Type="DateTime"></asp:ControlParameter>
                    <asp:ControlParameter ControlID="RadDatePickerEndDate" PropertyName="SelectedDate" Name="endDate" Type="DateTime"></asp:ControlParameter>
                </SelectParameters>
            </asp:SqlDataSource>
            <asp:SqlDataSource ID="SqlDataSourcePartnerQuestionDetails" runat="server" ConnectionString="<%$ ConnectionStrings:mdpSupportServices %>" SelectCommand="rpt_SurveyData_Partner_Question_Details" SelectCommandType="StoredProcedure">
                <SelectParameters>
                    <asp:SessionParameter Name="PartnerID" SessionField="PartnerID" Type="Int64" />
                    <asp:ControlParameter ControlID="RadDatePickerStartDate" Name="StartDate" PropertyName="SelectedDate" Type="DateTime" />
                    <asp:ControlParameter ControlID="RadDatePickerEndDate" Name="EndDate" PropertyName="SelectedDate" Type="DateTime" />
                </SelectParameters>
            </asp:SqlDataSource>

     

     

     here is my code behind

     

    protected void Page_Load(object sender, EventArgs e)
        {
            mdpBaseComponent.PageTitle = "Solution Reach Survey Report";
            mdpBaseComponent.PageSubTitle = "mdpSupportServices/SolutionReach_SurveyReport";
            if (!IsPostBack)
            {
                this.RadDatePickerStartDate.SelectedDate = DateTime.Now.AddMonths(-1);
                this.RadDatePickerEndDate.SelectedDate = DateTime.Now;
                Session.Clear();
            }
            else
            {
                //postback!!!
            }
             
        }

    protected void RadGrid_ItemCommand(object sender, GridCommandEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                GridDataItem item = (GridDataItem)e.Item;
                if (item.OwnerGridID == "RadGrid1")
                {
                    Session["PartnerID"] = item["PartnerID"].Text;
                }
                if (e.CommandName == "RowClick")
                {
                     //do nothing
                }
                else if (e.CommandName == Telerik.Web.UI.RadGrid.ExpandCollapseCommandName)
                {
                    item.Selected = true;
                }
                 
            }
        }
         
        protected void RadGrid_ColumnCreated(object sender, GridColumnCreatedEventArgs e)
        {
            if (e.Column is GridBoundColumn)
            {
                GridBoundColumn gbc = ((GridBoundColumn)e.Column);
                int n;
                if (gbc.HeaderText == "Partner ID")
                {
                    gbc.Display = false;
                }
                else if (gbc.HeaderText == "Venue ID")
                {
                    gbc.Display = false;
                }
                else if (gbc.HeaderText == "Partner Name")
                {
                    gbc.HeaderText = "Partner";
                }
                else if (gbc.HeaderText == "Venue Name")
                {
                    gbc.HeaderText = "Venue";
     
                }
                else if (gbc.HeaderText == "num_patients")
                {
                    gbc.HeaderText = "Patients";
                    gbc.DataFormatString = "{0:n0}";
                    gbc.FooterStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Left;
                    gbc.FooterAggregateFormatString = "{0:n0}";
                    gbc.FooterStyle.Wrap = false;
                    gbc.Aggregate = Telerik.Web.UI.GridAggregateFunction.Sum;
                }
                else if (gbc.HeaderText == "num_responses")
                {
                    gbc.HeaderText = "Responses";
                    gbc.DataFormatString = "{0:n0}";
                    gbc.FooterStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Left;
                    gbc.FooterAggregateFormatString = "{0:n0}";
                    gbc.FooterStyle.Wrap = false;
                    gbc.Aggregate = Telerik.Web.UI.GridAggregateFunction.Sum;
                }
                else if (gbc.HeaderText == "avg_answer")
                {
                    gbc.HeaderText = "Avg";
                    gbc.FooterStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Left;
                    gbc.DataType = typeof(double);
                    gbc.DataFormatString = "{0:P1}";
                    gbc.FooterAggregateFormatString = "{0:P1}";
                    gbc.FooterStyle.Wrap = false;
                    gbc.Aggregate = Telerik.Web.UI.GridAggregateFunction.Avg;
                }
                else if (gbc.HeaderText[0] == 'Q' && int.TryParse(gbc.HeaderText.Substring(1,gbc.HeaderText.Length-1), out n))
                {
                    //if first letter is Q, and rest of string is integer
                    // Q1,Q2,Q3 etc...
                    gbc.FooterStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Left;
                    gbc.DataType = typeof(double);
                    gbc.DataFormatString = "{0:P1}";
                    gbc.FooterAggregateFormatString = "{0:P1}";
                    gbc.FooterStyle.Wrap = false;
                    gbc.Aggregate = Telerik.Web.UI.GridAggregateFunction.Avg;
                }
            }
        }
     
         
          //colorize cells based on value
        public Color cellColor(double val, Color currentColor)
        {
            Color red = ColorTranslator.FromHtml("#F26C72");
            Color green = ColorTranslator.FromHtml("#64C23E");
            Color yellow = ColorTranslator.FromHtml("#DFCA3F");
            Color lightGreen = ColorTranslator.FromHtml("#BEFFBE");
            if (val >= .85)
                return currentColor;
            else if (val >= .70)
                return yellow;
            else
                return red;
        }
     
        protected void RadGrid_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                GridDataItem item = (GridDataItem)e.Item;
                foreach (GridColumn col in item.OwnerTableView.AutoGeneratedColumns)
                {
                    if (col.DataType == typeof(double))
                    {
                        double value;
                        if (double.TryParse(DataBinder.Eval(item.DataItem, col.UniqueName).ToString(), out value))
                        {
                            item[col.UniqueName].BackColor = cellColor(value, item[col.UniqueName].BackColor);
                        }
                    }
                }
            }
        }

  2. Brad
    Brad avatar
    4 posts
    Member since:
    Sep 2015

    Posted 29 Sep 2015 Link to this post

    I am using version 2014.1.403 for my controls. I am unable to update as we have not updated the rest of our pages yet.
  3. Eyup
    Admin
    Eyup avatar
    3666 posts

    Posted 02 Oct 2015 Link to this post

    Hi Brad,

    Could you temporarily disable any AJAX on the page if present (RadAjaxManager, RadAjaxPanel, UpdatePanel, etc.) and enable your script debugger (FireBug or F12) to see whether there are any script or server errors interfering?

    Regards,
    Eyup
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  4. Brad
    Brad avatar
    4 posts
    Member since:
    Sep 2015

    Posted 02 Oct 2015 in reply to Eyup Link to this post

    I commented out all of the AJAX controls on my page, and when I went to retest my page, I received an error. Which is good, and bad.

    The error I am receiving is "System.NullReferenceException: Object reference not set to an instance of an object."

    Page behavior is the same as before though. Works fine on first load, any row, expanding second item throws the error" 

     I am now going through the debugger trying to find where I am referencing a null object, but I have had no such luck yet

  5. Eyup
    Admin
    Eyup avatar
    3666 posts

    Posted 07 Oct 2015 Link to this post

    Hello Brad,

    You can temporarily remove the server-side event handlers one by one and see whether the error is related to the general databinding of the hierarchy, or some code logic within the event handlers.

    Regards,
    Eyup
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  6. Brad
    Brad avatar
    4 posts
    Member since:
    Sep 2015

    Posted 07 Oct 2015 in reply to Eyup Link to this post

    I was reassigned to another project, so I have had to set this aside for now.

    I will update this thread with where I went wrong, as soon as I figure out where that is.

     

    Thanks for all the help!

  7. Eyup
    Admin
    Eyup avatar
    3666 posts

    Posted 12 Oct 2015 Link to this post

    Hello Brad,

    Please take your time to re-arrange the project and feel free to turn to us if you manage to root out the problem.

    Regards,
    Eyup
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
Back to Top