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

Single Column In DetailsTable

2 Answers 106 Views
Grid
This is a migrated thread and some comments may be shown as answers.
dave
Top achievements
Rank 1
dave asked on 06 Mar 2012, 04:11 PM

I am working with version 2011.3.1305.35 of the RadGrid. I have a wide grid with 19 columns. There is an additional field I need to add that contains comments, which by its self can be 1000 characters long. If I add that column to the end of the grid most of the data is cut off. What I want to do now is put that comments column in a details table so the user can click the expand icon and view the comments. I think I have it set up correctly however, there is code in the ItemCreated event that tries to run when the expand icon is clicked. What is the best way to determine if the item being created is part of the details table?

Here is how I have the set grid setup:

<telerik:RadGrid ID="tGrid" runat="server" AllowPaging="True" AllowCustomPaging="true"
                PageSize="500" AllowSorting="True" AutoGenerateColumns="False" CellSpacing="0"
                OnNeedDataSource="tGrid_NeedDataSource" AllowMultiRowSelection="true" OnItemCreated="tGrid_ItemCreated"
                OnDataBound="tGrid_DataBound">
                <PagerStyle AlwaysVisible="True" Position="Top" />
                <MasterTableView Width="100%" DataKeyNames="schedID" ClientDataKeyNames="schedID">
                 <Columns> .... </Columns>
                    <DetailTables>
                        <telerik:GridTableView AdditionalDataFieldNames="schedComments" DataKeyNames="SchedID">
                            <Columns>
                                <telerik:GridBoundColumn DataField="schedComments" Display="true" UniqueName="schedComments"
                                    SortExpression="schedComments">
                                    <HeaderStyle Width="100%"></HeaderStyle>
                                    <ItemStyle Wrap="true" />
                                </telerik:GridBoundColumn>
                            </Columns>
                        </telerik:GridTableView>
                    </DetailTables>
                </MasterTableView>
</telerik:RadGrid>

2 Answers, 1 is accepted

Sort by
0
Accepted
Casey
Top achievements
Rank 1
answered on 06 Mar 2012, 05:15 PM
Hi Dave,

There is a Name property for the MasterTableView and the GridTableView. If you set the Name property for these, then you will able to check in the ItemCreated event whether the item is part of the master, or detail table.

I hope this helps!
Casey

protected void tGrid_ItemCreated(object sender, GridItemEventArgs e)
{
   if (e.Item is GridDataItem)
   {
      if (e.Item.OwnerTableView.Name == "Detail")
      {
         //Gets a reference to the current GridDataItem
         GridDataItem dataItm = e.Item as GridDataItem;
 
         //Gets a reference to the current GridDataItem's Parent GridDataItem
         GridDataItem parItm = e.Item.OwnerTableView.ParentItem;
      }
      else
      {
          
      }
   }
}
0
dave
Top achievements
Rank 1
answered on 06 Mar 2012, 05:19 PM
Thanks for the quick reply. I think I was making it more complicated than it needed to be. I just used a NestedViewTemplate instead:

 

<NestedViewTemplate>
     <asp:Label runat="server" Text='<%# Eval("schedComments") %>'></asp:Label>
</NestedViewTemplate>
Tags
Grid
Asked by
dave
Top achievements
Rank 1
Answers by
Casey
Top achievements
Rank 1
dave
Top achievements
Rank 1
Share this question
or