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

[Solved] Detailtable lost

5 Answers 182 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Markus
Top achievements
Rank 2
Markus asked on 25 Jun 2008, 01:39 PM
Hello!

I have a radgrid with a detailtable that is preloaded and expanded at the clientside.
If I switch to editmode, The detailtable is lost but the row is expanded - the expanded symbol is there but no table underneath.

Here is the aspx code:

<telerik:RadGrid ID="rgFiles" runat="server" 
    Skin="Office2007" 
    AllowAutomaticDeletes="false" 
    meta:resourcekey="radGrid" 
    AllowAutomaticInserts="false" 
    AllowAutomaticUpdates="false" 
    AllowMultiRowEdit="false" 
    AllowMultiRowSelection="false" 
    AllowSorting="true" 
    AllowPaging="true" 
    PageSize="10" 
    OnNeedDataSource="rgFiles_NeedDataSource" 
    OnDeleteCommand="rgFiles_Delete" 
    OnItemCommand="rgFiles_ItemCommand" 
    OnDetailTableDataBind="rgFiles_DetailTableDataBind" 
    AutoGenerateColumns="false"> 
    <PagerStyle Mode="NumericPages" /> 
    <ClientSettings> 
        <Selecting AllowRowSelect="true" /> 
    </ClientSettings> 
    <MasterTableView DataKeyNames="Id" HierarchyLoadMode="Client" EditMode="InPlace"> 
        <Columns> 
        <telerik:GridButtonColumn 
                    ButtonType="ImageButton" 
                    UniqueName="Download" 
                    CommandName="ItemCommand" 
                    ImageUrl="~/Img/Type.gif" 
                    CommandArgument="download"> 
            </telerik:GridButtonColumn> 
 
      <telerik:GridBoundColumn meta:resourcekey="colFilename" ReadOnly="true" 
                UniqueName="Filename" DataField="Filename" > 
            </telerik:GridBoundColumn> 
 
     <telerik:GridBoundColumn ReadOnly="true" 
                Visible="false" UniqueName="Mimetype" DataField="Mimetype" > 
            </telerik:GridBoundColumn> 
 
    <telerik:GridBoundColumn meta:resourcekey="colSize" ReadOnly="true" 
                UniqueName="Size" DataField="Size" > 
            </telerik:GridBoundColumn> 
 
    <telerik:GridBoundColumn meta:resourcekey="colCreateDate" ReadOnly="true" 
        UniqueName="CreationDate" DataField="CreationDate" > 
    </telerik:GridBoundColumn> 
 
        <telerik:GridButtonColumn 
                    meta:resourcekey="colDelete" 
                    UniqueName="DeleteColumn"   
                    CommandName="Delete" 
                    ButtonType="ImageButton" 
                    ImageurL="~/Img/delete.gif" 
                    Display="false"> 
        </telerik:GridButtonColumn> 
        </Columns> 
   <DetailTables> 
            <telerik:GridTableView  Name="Keywords" 
                                    EditMode="InPlace" 
                                    ShowFooter="False" 
                                    meta:resourcekey="detailtable"> 
                <columns> 
                    <telerik:GridTemplateColumn UniqueName="colKeywords"> 
                    <HeaderStyle Width="200px"></HeaderStyle> 
                    <HeaderTemplate> 
                        <asp:Label meta:resourcekey="lblHeadKeywords" ID="lblHeadKeywords" runat="server" ></asp:Label> 
                    </HeaderTemplate> 
                    <ItemTemplate> 
                        <p> 
                            <asp:Label meta:resourcekey="lblKeywords" ID="lblKeywords"  
                            runat="server" Text='<%# Eval("SearchField") %>' Width="100%"> 
                            </asp:Label> 
                        </p> 
                    </ItemTemplate> 
                     <EditItemTemplate> 
                        <p> 
                        <asp:TextBox ID="txtKeywords" runat="server" Text='<%# Eval("SearchField") %>' TextMode="MultiLine" > 
                        </asp:TextBox> 
                        </p> 
                      </EditItemTemplate> 
                    </telerik:GridTemplateColumn> 
                    <telerik:GridEditCommandColumn FooterText="EditCommand footer" 
                        UniqueName="EditCommandColumn" HeaderText="Edit&#160;Command Column"> 
                    </telerik:GridEditCommandColumn> 
                </columns> 
                </telerik:GridTableView> 
        </DetailTables> 
    </MasterTableView> 
</telerik:RadGrid> 
 
and heres the databinding source:

  protected void rgFiles_NeedDataSource(object sender, GridNeedDataSourceEventArgs e) 
        { 
            if (this.files == null) 
            { 
                if (this.NeedDataSource != null) 
                { 
                    AddFileEventArgs afea = new AddFileEventArgs(); 
                    afea.FileOwnerId = this.OwnerId; 
                    this.NeedDataSource(this, afea); 
                    this.files = afea.Files;             
                } 
            } 
            if (sender is RadGrid) 
            { 
                (sender as RadGrid).DataSource = this.files; 
            } 
        } 
 
  protected void rgFiles_DetailTableDataBind(object sender, GridDetailTableDataBindEventArgs e) 
        { 
            ICollection<IPortalFile> coll = null; 
            if (rgFiles.DataSource != null) 
            { 
                coll = rgFiles.DataSource as ICollection<IPortalFile>; 
            } 
            if (coll == null && this.files != null) 
            { 
                coll = this.files; 
            } 
 
            if (coll == null) 
                return; 
            string id = (string) e.DetailTableView.ParentItem.GetDataKeyValue("Id"); 
 
            foreach (IPortalFile file in coll) 
            { 
                if (file.Id.Equals(id)) 
                { 
                    e.DetailTableView.DataSource = new IPortalFile[]{ file }; 
                } 
            } 
             
        } 
 
 
        protected void OnPreRender(object sender, EventArgs e) 
        { 
            this.DataBind(); 
            if (this.enabled) 
            { 
                this.btnAddFile.CssClass = CSS_ENABLED; 
                this.rgFiles.Columns[this.rgFiles.Columns.Count - 1].Display = true; 
            } 
            else 
            { 
                this.btnAddFile.CssClass = CSS_DISABLED; 
                this.rgFiles.Columns[this.rgFiles.Columns.Count - 1].Display = false; 
            } 
            this.rgFiles.Rebind(); 
        } 
 

Thx in advance & kind regards

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 26 Jun 2008, 07:14 AM
Hi Markus,

You should never call the DataBind() method from inside the NeedDataSource handler or mix simple data-binding mode with advanced data-binding.
Go through the online demo for more details.
Advanced data-binding

Princy.
0
Markus
Top achievements
Rank 2
answered on 26 Jun 2008, 07:20 AM
Could you please go into further detail?

Where do I call the .DataBind() Method from inside the NeedDataSource Method??

And where do I mix up simple DataBinding and AdvancedDataBinding ?

regards!
0
Shinu
Top achievements
Rank 2
answered on 26 Jun 2008, 07:35 AM
Hi Markus,

Try setting runat="server" for the Detail table and see whether it is working

ASPX:
<DetailTables>  
            <telerik:GridTableView runat="server"  Name="Keywords"  
                                    EditMode="InPlace"  
                                    ShowFooter="False"  
                                    meta:resourcekey="detailtable">  


Thanks
Shinu.

0
Markus
Top achievements
Rank 2
answered on 26 Jun 2008, 09:43 AM
Hi Shinu!

setting the runat attribute is of course good practice :-) I tempt to forget it again and again :)

Anyway, this was no solution for the problem.

0
Sebastian
Telerik team
answered on 30 Jun 2008, 11:07 AM
Hello Markus,

Indeed the expanded state of the parent item will be lost on edit operation since this is one of the commands which invoke the Rebind() method of the grid implicitly. You can see that in the following online demo as well:

http://www.telerik.com/DEMOS/ASPNET/Prometheus/Grid/Examples/DataEditing/ThreeLevel/DefaultCS.aspx

If you would like to keep the expanded state of the hierarchy when editing parent records, consider storing the indices of the expanded items and recovering them afterwards as illustrated in the project from the following code library entry:

http://www.telerik.com/community/code-library/submission/b311D-ghhmh.aspx

Best regards,
Stephen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
Markus
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Markus
Top achievements
Rank 2
Shinu
Top achievements
Rank 2
Sebastian
Telerik team
Share this question
or