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

Trying to get a Heiarchy grid to update the nested grid

2 Answers 66 Views
Grid
This is a migrated thread and some comments may be shown as answers.
jms
Top achievements
Rank 1
jms asked on 01 Jul 2010, 08:43 PM
Situation,
  I have a hierarchy grid where in the nested grid a link pops up a modal pop-up so the user can edit all of the contents of the object, the nested grid only shows a selected portion.  upon saving all is good except the nested grid, I cannot seem to figure out how to refresh it, unless I reload the entire page which I guess would work but not preferable.  would like to just refresh the nested grid but will settle for the whole grid if need be.


Aspx Code:

<asp:UpdatePanel ID="upnlGrid" runat="server" UpdateMode="Conditional"
<ContentTemplate> 
    <telerik:RadGrid ID="UnitList" runat="server" AutoGenerateColumns="False"  
        DataSourceID="UnitDataSource" GridLines="None"   
         Skin="Windows7"
<MasterTableView datakeynames="Id" datasourceid="UnitDataSource"
    <DetailTables> 
        <telerik:GridTableView runat="server" DataKeyNames="Id"  
            CssClass="GridBackground"
            <RowIndicatorColumn> 
                <HeaderStyle Width="20px" /> 
            </RowIndicatorColumn> 
            <ExpandCollapseColumn> 
                <HeaderStyle Width="20px" /> 
            </ExpandCollapseColumn> 
            <Columns> 
                <telerik:GridTemplateColumn DataField="Title" HeaderText="Title"  
                    UniqueName="LTitle"
                    <ItemTemplate> 
                        <asp:LinkButton ID="lbtnLTitle" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "Id")%>' runat="server" OnClick="lbtnLTitle_Click" Text='<%# DataBinder.Eval(Container.DataItem, "Title") %>'></asp:LinkButton> 
                    </ItemTemplate> 
                </telerik:GridTemplateColumn> 
                <telerik:GridBoundColumn DataField="Presenter" HeaderText="Presenter"  
                    UniqueName="LPresenter"
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="Location" HeaderText="Location"  
                    UniqueName="LLocation"
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="Hours" HeaderText="Hours"  
                    UniqueName="LHours"
                </telerik:GridBoundColumn> 
                <telerik:GridCheckBoxColumn DataField="IsActive" DataType="System.Boolean"  
                    HeaderText="Active" UniqueName="LIsActive"
                </telerik:GridCheckBoxColumn> 
            </Columns> 
        </telerik:GridTableView> 
    </DetailTables> 
<RowIndicatorColumn> 
<HeaderStyle Width="20px"></HeaderStyle> 
</RowIndicatorColumn> 
<ExpandCollapseColumn visible="True"
<HeaderStyle Width="20px"></HeaderStyle> 
</ExpandCollapseColumn> 
    <Columns> 
        <telerik:GridTemplateColumn DataField="Title" HeaderText="Title"  
            UniqueName="UTitle"
             <ItemTemplate> 
                        <asp:LinkButton ID="lbtnUTitle" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "Id")%>' runat="server" OnClick="lbtnUTitle_Click" Text='<%# DataBinder.Eval(Container.DataItem, "Title") %>'></asp:LinkButton> 
                    </ItemTemplate> 
        </telerik:GridTemplateColumn> 
        <telerik:GridBoundColumn DataField="OfferDept" HeaderText="Offer Dept."  
            UniqueName="UOfferDept"
        </telerik:GridBoundColumn> 
        <telerik:GridBoundColumn DataField="Semester" HeaderText="Semester"  
            UniqueName="USemester"
        </telerik:GridBoundColumn> 
        <telerik:GridBoundColumn DataField="Type" HeaderText="Type" UniqueName="UType"
        </telerik:GridBoundColumn> 
        <telerik:GridBoundColumn DataField="StudentVuNetId" HeaderText="Student Id"  
            UniqueName="UStudentVuNetId"
        </telerik:GridBoundColumn> 
        <telerik:GridBoundColumn DataField="Hours" HeaderText="Hours"  
            UniqueName="UHours"
        </telerik:GridBoundColumn> 
        <telerik:GridCheckBoxColumn DataField="IsActive" DataType="System.Boolean"  
            HeaderText="Active" UniqueName="UIsActive"
        </telerik:GridCheckBoxColumn> 
    </Columns> 
</MasterTableView> 
    </telerik:RadGrid> 
    <asp:ObjectDataSource ID="UnitDataSource" runat="server"  
        SelectMethod="GetAllUnits"  
        TypeName="Vanderbilt.CpmmProg.CommonUtils.UnitManagement"
    </asp:ObjectDataSource> 
</ContentTemplate> 
</asp:UpdatePanel>   


C# Code:
protected void Page_Load(object sender, EventArgs e) 
        { 
             
            //attach the event to build the nested grid 
            UnitList.DetailTableDataBind += new GridDetailTableDataBindEventHandler(UnitList_DetailTableDataBind); 
             
            if (!Page.IsPostBack) 
            { 
                //do some stuff not related to grid at all 
            } 
        } 
 
 
        protected void UnitList_DetailTableDataBind(object source, GridDetailTableDataBindEventArgs e) 
        { 
            int unitId = (int)e.DetailTableView.ParentItem.GetDataKeyValue("Id"); 
            e.DetailTableView.DataSource = UnitManagement.GetUnitLectures(unitId); 
        } 
 
        protected void lbtnLTitle_Click(object sender, EventArgs e) 
        { 
            int Id = Int32.Parse(((LinkButton)sender).CommandArgument.ToString().Trim()); 
             
            //TODO Get data for lecture, populate the updatePanel for editing lectures 
            Lecture lec = LectureManagement.GetLecture(Id); 
            tbTitle.Text = lec.Title; 
            tbPresenter.Text = lec.Presenter; 
            tbLocation.Text = lec.Location; 
            tbHours.Text = lec.Hours.ToString(); 
            tbCourseAdminVuNetId.Text = lec.CourseAdminVuNetId; 
            rdtpTime.SelectedDate = lec.DateAndTime; 
            hfEditLecId.Value = lec.Id.ToString(); 
            cbIsActive.Checked = lec.IsActive; 
            //TODO show modal popup. 
            hfEditLectureDummy_ModalPopupExtender.Show(); 
        } 
 
 
 
        protected void lbtnUTitle_Click(object sender, EventArgs e) 
        { 
             //redirect to another page 
        } 
 
        protected void btnEditCancel_Click(object sender, EventArgs e) 
        { 
            //hide the modal popup 
            hfEditLectureDummy_ModalPopupExtender.Hide(); 
        } 
 
        protected void btnEditSave_Click(object sender, EventArgs e) 
        { 
            //get the lecture 
            //save the lecture to persistence 
 
            //hide modal popup 
            hfEditLectureDummy_ModalPopupExtender.Hide(); 
 
            //update the updatepanel 
            upnlGrid.Update(); 
        } 


thanks,
jms

2 Answers, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 07 Jul 2010, 09:16 AM
Hello James,

You could try the following approach:

On RadGrid.ItemDataBound event handler you could store into the Session the updated item's OwnerTableView:
public GridTableView Item
{
     get
     {
         if(Session["GridTableView"] == null)
         {
             return null;
         }
         else
         {
             return (Session["GridTableView"] as GridTableView);
         }
     }
     set
     {
         Session["GridTableView"] = value;
     }
 }
void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
     if (e.Item.IsInEditMode)
     {
         Item = e.Item.OwnerTableView;
     }
}

Then on btnEditSave's click event you could rebind the nested table view:
protected void btnEditSave_Click(object sender, EventArgs e)
{
    //get the lecture
    //save the lecture to persistence
 
    //hide modal popup
    hfEditLectureDummy_ModalPopupExtender.Hide();
 
    //refresh the nested table view
    Item.Rebind();
}

I hope this helps

Regards,
Radoslav
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
jms
Top achievements
Rank 1
answered on 18 Aug 2010, 10:33 PM
Thanks for the solution, I did not think of doing that.  It worked just to let you know, but there wasa design change and  that was no longer needed.

jimm
Tags
Grid
Asked by
jms
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
jms
Top achievements
Rank 1
Share this question
or