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

[Solved] NestedViewTemplate Not Rebinding with MasterTableView

1 Answer 195 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kevin Kembel
Top achievements
Rank 1
Kevin Kembel asked on 12 Feb 2010, 09:32 PM
I would think that either this is a stupid mistake I'm making, or someone else has at least had this problem, but I couldn't find any specific help in other posts, so here I go...

I have a NestedViewTemplate with a UserControl.  I bind a couple of my UserControl properties to the row DataItem values. In my user control, there are a few buttons that change values on the grid (we'll say "Status" changes for this example).  In the user control, if I update the "Status" of a row, I have to rebind the grid for the changes to show up.  That all works fine, except when I call gridResumes.Rebind(), it shows the changes, but my NestedView is not showing anymore, the row is not expanded.

My solution was to have an event fire when you change a row using the NestedViewTemplate that tells me which row was changed.  I then set "gridResumes.Items[updatedItemIndex].Expanded = true;" so that after the postback, the item is still expanded. 

My problem is, calling Rebind() reloads the column data, but the NestedTableView is not bound to anything, the values within my user control are null.  Why does Rebind() not rebind the NestedTableView?  Do I have to call that manually after setting Expanded=true?

    <telerik:RadGrid ID="gridResumes" runat="server" AllowPaging="true"   
        AllowSorting="true" onneeddatasource="gridResumes_NeedDataSource"   
        AllowFilteringByColumn="true" CssClass="resumeGrid">  
        <GroupingSettings CaseSensitive="false" /> 
        <ClientSettings EnableRowHoverStyle="true" /> 
          
        <MasterTableView DataKeyNames="RecruitmentPortalGUID" AutoGenerateColumns="false">  
          
            <Columns> 
                <telerik:GridBoundColumn HeaderText="Last Name" UniqueName="LastName"   
                    SortExpression="LastName" DataField="LastName"></telerik:GridBoundColumn> 
                <telerik:GridBoundColumn HeaderText="First Name" UniqueName="FirstName"   
                    SortExpression="FirstName" DataField="FirstName"></telerik:GridBoundColumn> 
                <telerik:GridBoundColumn HeaderText="Position" UniqueName="AppliedPositionShort"   
                    SortExpression="AppliedPositionShort" DataField="AppliedPositionShort"></telerik:GridBoundColumn> 
                <telerik:GridBoundColumn HeaderText="Quiz" UniqueName="QuizTotal"   
                    SortExpression="QuizTotal" DataField="QuizTotal"></telerik:GridBoundColumn> 
                <telerik:GridBoundColumn HeaderText="Applied" UniqueName="DateCreated"   
                    SortExpression="DateCreated" DataField="DateCreated" DataFormatString="{0:MM/dd/yyyy}"></telerik:GridBoundColumn> 
                <telerik:GridTemplateColumn HeaderText="Status" UniqueName="Status" SortExpression="Status" DataField="Status">  
                    <ItemTemplate> 
                        <span class='<%# "resumeGrid_item_status_" + Eval("Status").ToString().ToLower() %>'><%# Eval("Status") %></span>  
                    </ItemTemplate> 
                </telerik:GridTemplateColumn> 
            </Columns> 
              
            <NestedViewTemplate> 
                <asp:HiddenField ID="hiddenRecruitmentPortalGuid" runat="server" Value='<%# Eval("RecruitmentPortalGUID") %>' /> 
                <asp:Panel ID="pnlResumeDetails" runat="server" CssClass="resumeItem_details">  
                    <custom:ResumeDetails ID="resumeDetails" runat="server"   
                        RecruitmentPortalGuid='<%# Eval("RecruitmentPortalGUID") %>' ItemIndex='<%# ((Telerik.Web.UI.GridNestedViewItem)Container).ParentItem.ItemIndex %>'   
                        OnHide="resumeDetails_Hide" OnShow="resumeDetails_Show" OnInterview="resumeDetails_Interview" 
                        OnHire="resumeDetails_Hire" OnRelease="resumeDetails_Release" /> 
                </asp:Panel> 
            </NestedViewTemplate> 
              
        </MasterTableView> 
          
    </telerik:RadGrid> 

1 Answer, 1 is accepted

Sort by
0
Kevin Kembel
Top achievements
Rank 1
answered on 12 Feb 2010, 09:38 PM
I'm sorry, I spent hours trying to figure this out, and then took a break, went back to it and got it working.  Here's what I had to do in case anyone else has this problem.  I was missing exactly what I thought I was, I just didn't know where to find it.  To rebind an item's NestedViewTemplate manually after expanding it:

    protected void nestedUserControl_PostBack(object sender, UCEventArgs e)  
    {  
        RadGrid1.Rebind();  
        if (e.ItemIndex >= 0)  
        {  
            RadGrid1.Items[e.ItemIndex].Expanded = true;  
            RadGrid1.Items[e.ItemIndex].ChildItem.DataBind();  
        }  
    } 

I bound the "ItemIndex" value to a public property in the UserControl so that the UserControl knows its index in the grid.  It then passes the index back to the subscriber to any of the postback events so that my main grid can capture the event, tell which item is causing a postback, and expand that row and databind it.

Hope that helps someone else.
Tags
Grid
Asked by
Kevin Kembel
Top achievements
Rank 1
Answers by
Kevin Kembel
Top achievements
Rank 1
Share this question
or