RadGrid Expand/Collapse on Row click

=================================

ASPX -  like HierarchyExpandCollapseOnDoubleClick_WebUI.zip

http://www.telerik.com/community/code-library/aspnet-ajax/grid/expand-collapse-hierarchy-with-ajax-request-on-double-click.aspx

=================================

<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">

        <script type="text/javascript"> 
                function RowDblClicked(sender, args)
               {
                   var tableName=args.get_tableView().get_id();
                   if (tableName.indexOf("radgridEmbedded")==-1 )
                      {
                          var arguments = "Expand|" + args.get_tableView().get_id() + "|" + args.get_itemIndexHierarchical();
                          $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest(arguments);
                      }
                }       

            </script>

</telerik:RadCodeBlock >

 

<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" Skin="Telerik"
         DataSourceID="SqlDataSource1">
         <MasterTableView DataKeyNames="CustomerID" AllowPaging="true" PageSize="5" DataSourceID="SqlDataSource1"
             ClientDataKeyNames="CustomerID" Name="Customers">
             <PagerStyle Mode="NumericPages" />
             <Columns>     …       </Columns>
             <DetailTables>…        </DetailTables>
                 </telerik:GridTableView>
             </DetailTables>
         </MasterTableView>
         <ClientSettings>
             <ClientEvents OnRowDblClick="RowDblClicked"></ClientEvents>
         </ClientSettings>
     </telerik:RadGrid>

=================================

C# codes -  like HierarchyExpandCollapseOnDoubleClick_WebUI.zip

http://www.telerik.com/community/code-library/aspnet-ajax/grid/expand-collapse-hierarchy-with-ajax-request-on-double-click.aspx

=================================

protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
    {
      if (e.Argument.IndexOf("|") >= 0)
        {
            string[] postBackData = e.Argument.Split('|');
            switch (postBackData[0])
            {
                case "Expand":
                    //Dim item As GridDataItem = CType(GetTableView(Me.RadGrid1.MasterTableView, postBackData(1)).Controls(0), Table).Rows(postBackData(2))
                    int index = postBackData[2].LastIndexOf("_");
                    int tableIndex = int.Parse(postBackData[2].Substring(index + 1));

                    GridDataItem item = GetTableView(this.RadGrid1.MasterTableView, postBackData[1]).Items[tableIndex];
                    if (item.Expanded)
                    {
                        item.FireCommandEvent(RadGrid.ExpandCollapseCommandName, new EventArgs());
                        item.Expanded = false;
                    }
                    else
                    {
                        item.FireCommandEvent(RadGrid.ExpandCollapseCommandName, new EventArgs());
                        item.Expanded = true;
                    }

                    break;
            }
        }
    }

 

private GridTableView GetTableView(GridTableView currTableView, string controlId)
  {
      if (currTableView.ClientID == controlId)
      {
          return currTableView;
      }
      else
      {
          foreach (GridItem item in currTableView.Items)
          {
              if (item.HasChildItems & item is GridDataItem)
              {
                  foreach (GridTableView nestedView in ((GridDataItem)item).ChildItem.NestedTableViews)
                  {
                      GridTableView res = GetTableView(nestedView, controlId);
                      if (res != null)
                      {
                          return res;
                      }
                  }
              }
          }
      }
      return null;
  }

 

 

REF:

http://www.telerik.com/community/forums/aspnet/grid/expand-collapse-on-row-click.aspx

http://www.telerik.com/community/forums/aspnet-ajax/grid/expand-by-row-click.aspx

http://www.telerik.com/community/code-library/aspnet-ajax/grid/expand-collapse-hierarchy-with-ajax-request-on-double-click.aspx

http://www.telerik.com/community/code-library/aspnet-ajax/grid/expand-collapse-hierarchy-client-side-on-double-click.aspx

http://www.telerik.com/community/forums/aspnet-ajax/grid/expand-nestedview-on-row-click.aspx

http://www.telerik.com/community/forums/aspnet/grid/expand-grid-on-select.aspx

你可能感兴趣的:(click)