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

Access Radgrid in Nestedviewtemplate

7 Answers 141 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Manuel
Top achievements
Rank 1
Manuel asked on 29 Jul 2013, 06:06 AM


 Hi,

 I Tried to acces RadGrid2, but i cannot acces it.
How is it possible to access Radgrid2?

Radgrid2 is within a radtap

Hope you can help me


     </asp:ScriptManager>
    <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateHierarchy="True" CellSpacing="0" Culture="de-DE" GridLines="None">
<MasterTableView>
<CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
 
<RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
 
<ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
    <NestedViewTemplate>
                    <asp:Panel runat="server" ID="configControlContainer" CssClass="viewWrap" Visible="true">
                                            <telerik:RadTabStrip runat="server" ID="TabStrip1" MultiPageID="Multipage1" SelectedIndex="0">
                        <Tabs>
                            <telerik:RadTab runat="server" Text="Satzart 2" PageViewID="PageView1">
                                                       </telerik:RadTab>
                            <telerik:RadTab runat="server" Text="Satzart 3" PageViewID="PageView2">
                            </telerik:RadTab>
                            <telerik:RadTab runat="server" Text="Satzart 4" PageViewID="PageView3">
                            </telerik:RadTab>  </Tabs>
                    </telerik:RadTabStrip>
                         
                            <telerik:RadMultiPage runat="server" ID="Multipage1" SelectedIndex="0" RenderSelectedPageOnly="false">
                        <telerik:RadPageView runat="server" ID="PageView1">
                             
                           <telerik:RadGrid ID="RadGrid2" runat="server"    AutoGenerateHierarchy="True" CellSpacing="0" Culture="de-DE" GridLines="None"/>
                             
                        </telerik:RadPageView>
                        </telerik:RadMultiPage>
 
                       
                    </asp:Panel>
                </NestedViewTemplate>
    <Columns>
        <telerik:GridBoundColumn DataField="id" FilterControlAltText="Filter column column" UniqueName="column">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="Satzart" FilterControlAltText="Filter column1 column" UniqueName="column1">
        </telerik:GridBoundColumn>
   
             
              
           
    </Columns>

7 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 29 Jul 2013, 09:57 AM
Hi Manuel,

Please try the below sample code snippet to access a radgrid in nestedview template.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource"
    AllowPaging="true" OnItemCommand="RadGrid1_ItemCommand">
    <MasterTableView DataKeyNames="CustomerID">
        <NestedViewTemplate>
            <asp:Panel runat="server" ID="Panel1" Visible="true">
                <telerik:RadTabStrip runat="server" ID="TabStrip1" MultiPageID="Multipage1" SelectedIndex="0">
                    <Tabs>
                        <telerik:RadTab runat="server" Text="Page 1" PageViewID="PageView1">
                        </telerik:RadTab>
                    </Tabs>
                </telerik:RadTabStrip>
                <telerik:RadMultiPage runat="server" ID="Multipage1" SelectedIndex="0" RenderSelectedPageOnly="false">
                    <telerik:RadPageView runat="server" ID="PageView1">
                        <telerik:RadGrid ID="RadGrid2" runat="server" AllowPaging="true" PageSize="5" OnNeedDataSource="RadGrid2_NeedDataSource" />
                    </telerik:RadPageView>
                </telerik:RadMultiPage>
            </asp:Panel>
        </NestedViewTemplate>
    </MasterTableView>
</telerik:RadGrid>

C#:
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
  {
      RadGrid1.DataSource = GetDataTable("SELECT CustomerID, CompanyName, ContactTitle FROM Customers");
  }
  protected void RadGrid2_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
  {
      GridDataItem parentItem = ((sender as RadGrid).NamingContainer as GridNestedViewItem).ParentItem as GridDataItem;
      (sender as RadGrid).DataSource = GetDataTable("SELECT OrderID, EmployeeID, CustomerID FROM Orders where CustomerID='" + parentItem.GetDataKeyValue("CustomerID").ToString() + "'");
  }
  protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
  {
      if (e.CommandName == RadGrid.ExpandCollapseCommandName && !e.Item.Expanded)
      {
          GridDataItem parentItem = e.Item as GridDataItem;
          RadGrid grid = parentItem.ChildItem.FindControl("RadGrid2") as RadGrid;
          grid.Rebind();
      }
  }

Thanks,
Princy
0
Manuel
Top achievements
Rank 1
answered on 30 Jul 2013, 11:17 AM
Thank you very much that worked for me :)

Now i have another problem.
as i said before, i have a grid. In this grid there are a radmultipage with radtabs. In the radtabs there are 6 Radgrids for each of my six tabs.
No i want the radgrid to resizetofit, but it doesn´t worked.

Here´s my code snippet from the resize method:

<%--    <script>
                  function pageLoad() {
                      var grid = $find("RadGrid2");
                      var columns = grid.get_masterTableView().get_columns();
                      for (var i = 0; i < columns.length; i++) {
                          columns[i].resizeToFit();
                      }
 
                          var grid = $find("RadGrid3");
                          var columns = grid.get_masterTableView().get_columns();
                          for (var i = 0; i < columns.length; i++) {
                              columns[i].resizeToFit();
                          }
                              var grid = $find("RadGrid4");
                              var columns = grid.get_masterTableView().get_columns();
                              for (var i = 0; i < columns.length; i++) {
                                  columns[i].resizeToFit();
                              }
                                  var grid = $find("RadGrid5");
                                  var columns = grid.get_masterTableView().get_columns();
                                  for (var i = 0; i < columns.length; i++) {
                                      columns[i].resizeToFit();
                      }
                              }
 
              </script>--%>
0
Princy
Top achievements
Rank 1
answered on 30 Jul 2013, 11:34 AM
Hi Manuel,

Please try the following code snippet.The issue is in this line  "$find("RadGrid2")". Please correct the code as below and check if the issue persists.

ASPX:
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
    <script type="text/javascript">
        function pageLoad() {
            var grid = $find("<%= RadGrid2.ClientID %>");
            var columns = grid.get_masterTableView().get_columns();
            for (var i = 0; i < columns.length; i++) {
                columns[i].resizeToFit();
            }
        }
    </script>
</telerik:RadCodeBlock>

Let me know if any concern.

Thanks,
Princy
0
Manuel
Top achievements
Rank 1
answered on 31 Jul 2013, 06:58 AM
 Thank you very much, but unfortunately it doesnt work because Radgrid2 is not defined.
 To access the radgrid2 i have the following code:

Dim ChildGrid2 As New RadGrid
 
Dim nestedItem As GridNestedViewItem = DirectCast(source.mastertableview.items(e.Item.ItemIndex).ChildItem, GridNestedViewItem)
             ChildGrid2 = DirectCast(nestedItem.FindControl("RadGrid2"), RadGrid)
                ChildGrid2.AutoGenerateColumns = True

The Radgrid2 is within a Radpageview, so i have to navigate to the radgrid2
0
Princy
Top achievements
Rank 1
answered on 09 Aug 2013, 09:16 AM
Hi Manuel,

You can resize the child grid by setting the resize method in OnGridCreated event of the Child RadGrid.Please try the below code snippet.

ASPX:
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
           <script type="text/javascript">
               //For ParentGrid RadGrid1
               function pageLoad() {
                   var grid = $find("<%= RadGrid1.ClientID %>");
                   var columns = grid.get_masterTableView().get_columns();
                   for (var i = 0; i < columns.length; i++) {
                       columns[i].resizeToFit();
                   }
               }
               //For ChildGrid RadGrid2
               function GridCreated(sender, args) {
                   var grid = sender;
                   var columns = grid.get_masterTableView().get_columns();
                   for (var i = 0; i < columns.length; i++) {
                       columns[i].resizeToFit();
                   }
               }
           </script>
       </telerik:RadCodeBlock>
       <telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource">
           <MasterTableView DataKeyNames="CustomerID">
               <NestedViewTemplate>
                   <asp:Panel runat="server" ID="Panel1" >
                       <telerik:RadTabStrip runat="server" ID="TabStrip1" MultiPageID="Multipage1" SelectedIndex="0">
                           <Tabs>
                               <telerik:RadTab runat="server" Text="Page 1" PageViewID="PageView1">
                               </telerik:RadTab>
                           </Tabs>
                       </telerik:RadTabStrip>
                       <telerik:RadMultiPage runat="server" ID="Multipage1" SelectedIndex="0" RenderSelectedPageOnly="false">
                           <telerik:RadPageView runat="server" ID="PageView1">
                               <telerik:RadGrid ID="RadGrid2" runat="server" AllowPaging="true" PageSize="3" OnNeedDataSource="RadGrid2_NeedDataSource">
                                   <ClientSettings>
                                       <Resizing AllowColumnResize="true" ResizeGridOnColumnResize="true" AllowResizeToFit="true" />
                                       <ClientEvents OnGridCreated="GridCreated" />
                                   </ClientSettings>
                               </telerik:RadGrid>
                           </telerik:RadPageView>
                       </telerik:RadMultiPage>
                   </asp:Panel>
               </NestedViewTemplate>
           </MasterTableView>
           <ClientSettings Scrolling-AllowScroll="true">
               <Resizing AllowColumnResize="true" ResizeGridOnColumnResize="true" AllowResizeToFit="true" />
           </ClientSettings>
       </telerik:RadGrid>

Thanks,
Princy
0
Anatoly
Top achievements
Rank 1
answered on 20 Jul 2020, 12:02 PM

How to update the Tab.Text with some value, from Ajax on Client ( by javascript or jquery )  through Radgrid->NestedViewTemplate->RadTabStrip ?

<script>

function HierarchyExpanding(sender, args) {
   var ROWNUM= args.getDataKeyValue("ROWNUM");
         $.ajax({
          type: "POST",
          contentType: "application/json; charset=utf-8",
          url: "WebServices/GetData.asmx/getCountToParentisize",
 data: "{'ROWNUM':'" + ROWNUM+ "'}",
 dataType: "json",
 async: false,
 success: function (data) {
     var count = data[0].ROWNUM);
      ?????????    How update Tab.Text from here ??????            },
 error: function (request, status, error) { }
   });

</script>

 

<telerik:RadGrid runat="server" ID="RadGrid1"...>
<ClientSettings >
      <ClientEvents OnRowClick="OnRowClick"      OnHierarchyExpanding="HierarchyExpanding"  />
</ClientSettings>
<MasterTableView AutoGenerateColumns="true" ClientDataKeyNames="ROWNUM" DataKeyNames="ROWNUM">
      <NestedViewTemplate>
         <asp:Panel ID="pnl" runat="server">
              <telerik:RadTabStrip ID="rts" runat="server" MultiPageID="rmp" OnTabClick="rts_TabClick">
                 <Tabs>
                      <telerik:RadTab runat="server" Text="text1" PageViewID="rpv1" />
                      <telerik:RadTab runat="server" Text="text2" PageViewID="rpv2" />
 

0
Eyup
Telerik team
answered on 23 Jul 2020, 09:54 AM

Hi Anatoly,

 

The RadTab client-side object provides the set_text and set_value methods you can use to achieve this requirement:
https://docs.telerik.com/devtools/aspnet-ajax/controls/tabstrip/client-side-programming/objects/radtab-object

First, you will need to access the RadTabStrip control using the findControl method:
https://www.telerik.com/support/kb/aspnet-ajax/details/access-telerik-controls-on-client-side

Then, you can get the tab you want.

Finally, you can change its text using the set_text(...) method.

I hope this will prove helpful.

 

Regards,
Eyup
Progress Telerik

Tags
Grid
Asked by
Manuel
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Manuel
Top achievements
Rank 1
Anatoly
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or