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

Grid Expand/Collapse not working

4 Answers 335 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tracy
Top achievements
Rank 1
Tracy asked on 13 Feb 2011, 07:52 AM
Hi,

I have created a grid based on the demo Grid Programmatic Binding but can not get the grid to expand or collapse.  I added the following code to the pre-render event and the grid opens with the first item expanded and the data is displayed in the detail grid correctly.  But, when I try to collapse the row it will not collapse and none of the other rows will expand. 

Private

 

Sub rgvSecurityGroups_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles rgvSecurityGroups.PreRender
If Not Page.IsPostBack Then
    rgvSecurityGroups.MasterTableView.Items(0).Expanded = True
End If
End Sub

Below is the code for my page.  Thank you for your assistance.

Tracy

 

<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/IPSMaster.Master" CodeBehind="WBC SEC Security Groups.aspx.vb" Inherits="IPS_Gateway.WBC_SEC_Security_Groups" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="act" %>
    
<asp:Content ID="cntMain" ContentPlaceHolderID="cphMainContent" runat="server" >
  
  
<asp:SqlDataSource ID="SQLDS_SecurityGroups"     runat="server"  ConnectionString="<%$ ConnectionStrings:IPSDataConnectionString %>"  
        SelectCommandType="StoredProcedure" SelectCommand="[Security].[DSP_SecurityGroups-SEL-INS-UPD-DEL]"> 
        <SelectParameters>
            <asp:Parameter Name="strCommandType" Type="String" DefaultValue="Select" />
        </SelectParameters>
</asp:SqlDataSource>
  
<asp:SqlDataSource ID="SQLDS_SecurityGroupUsers"     runat="server"  ConnectionString="<%$ ConnectionStrings:IPSDataConnectionString %>"  
        SelectCommandType="StoredProcedure" SelectCommand="[Security].[DSP_SecurityGroupUsers-Select]" >
</asp:SqlDataSource>
  
<asp:panel ID="pnlPage"   runat="server"  SkinId="skn_GPC01_Panel_MainContent">      
  
     <telerik:RadAjaxManager ID="RadAjaxManager2"  runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="rgvSecurityGroups">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="rgvSecurityGroups" LoadingPanelID="RadAjaxLoadingPanel1" />
                    <telerik:AjaxUpdatedControl ControlID="rwmMessageBox" />
                    <telerik:AjaxUpdatedControl ControlID="rwmSecuritySettings" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" BackgroundPosition="Center"  ZIndex="150"  
        <asp:Image ID="imgLoading" runat="server" ImageUrl='<%$Resources:Images, LoadingBlack %>' AlternateText="Loading"   />
    </telerik:RadAjaxLoadingPanel>
    <asp:HiddenField ID="hdfSecurityId" runat="server" />
  
    <asp:panel ID="pnlPageHeader"                runat="server"  cssClass="css_GPC01_Panel_PageHeading" >       
        <asp:Label ID="txtPageTitle"             runat="server"  CssClass="css_GPC01_Label_PageTitle" Text="Security Groups" />   
        <asp:ImageButton ID="ibtPageInformation" runat="server"  SkinID="skn_GPC01_ImageButton_PageInformation"  />
    </asp:panel>    
  
    <asp:Panel ID="pnlPageContent"               runat="server"  CssClass="css_GPC01_Panel_PageContent" >     
        <telerik:RadGrid ID="rgvSecurityGroups"  runat="server"  DataSourceID="SQLDS_SecurityGroups"   
                EnableEmbeddedSkins = "true"    Skin="Black"
                AllowMultiRowSelection="false" 
                AllowAutomaticDeletes="True" 
                AllowAutomaticInserts="True"  
                AllowAutomaticUpdates="True"  
                AllowPaging="True" 
                EnableViewState ="true"                 
                AutoGenerateColumns="False"
                height="560px">
                                  
            <PagerStyle AlwaysVisible="true" Mode="NextPrevAndNumeric" />
            <ClientSettings AllowColumnsReorder="false" EnablePostBackOnRowClick="true" 
                            AllowExpandCollapse="true"  >  
                <Selecting AllowRowSelect="true" />
                <Scrolling AllowScroll="true" UseStaticHeaders="true" />
            </ClientSettings>
            <MasterTableView    DataSourceID="SQLDS_SecurityGroups" DataKeyNames="SecurityID"     
                EditMode="InPlace" CommandItemDisplay="Top"  PageSize="30"   >
                <CommandItemTemplate >
                    <div style="padding: 5px 5px;">
                        <asp:LinkButton ID="lbtAdd"          runat="server" CommandName="InitInsert"     ToolTip ="Add New Group"               Visible='<%# Not rgvSecurityGroups.MasterTableView.IsItemInserted %>'><asp:Image ID="imgAdd" runat="server" CssClass="css_GFS01_Image_Align" ImageURL="<%$ Resources:Images,AddRecord20%>" /> Add </asp:LinkButton>  
                        <asp:LinkButton ID="IbtEdit"         runat="server" CommandName="EditSelected"   ToolTip ="Edit Group"                  Visible='<%# rgvSecurityGroups.EditIndexes.Count = 0 and Not rgvSecurityGroups.MasterTableView.IsItemInserted %>'>          <asp:Image runat="server" CssClass="css_GFS01_Image_Align" ImageURL="<%$ Resources:Images, EditRecord20%>"/> Edit </asp:LinkButton>  
                        <asp:LinkButton ID="IbtCancel"       runat="server" CommandName="CancelAll"      ToolTip ="Cancel Edit/Add"             Visible='<%# rgvSecurityGroups.EditIndexes.Count > 0 Or rgvSecurityGroups.MasterTableView.IsItemInserted %>'><asp:Image ID="imgCancel" runat="server" CssClass="css_GFS01_Image_Align" ImageURL="<%$ Resources:Images,CancelRecord20%>" /> Cancel </asp:LinkButton>  
                        <asp:LinkButton ID="lbtSaveNew"      runat="server" CommandName="PerformInsert"  ToolTip ="Save New Group"              Visible='<%# rgvSecurityGroups.MasterTableView.IsItemInserted%>'><asp:Image ID="imgSaveNew" runat="server" CssClass="css_GFS01_Image_Align" ImageURL="<%$ Resources:Images,SaveRecord20%>" /> Save New</asp:LinkButton>  
                        <asp:LinkButton ID="lbtDelete"       runat="server" CommandName="DeleteSelected" ToolTip ="Delete Group"                Visible='<%# rgvSecurityGroups.EditIndexes.Count = 0 and Not rgvSecurityGroups.MasterTableView.IsItemInserted %>'><asp:Image ID="imgDelete"       runat="server" CssClass="css_GFS01_Image_Align" ImageURL="<%$ Resources:Images,DeleteRecord20%>" />Delete </asp:LinkButton>  
                        <asp:LinkButton ID="lbtSave"         runat="server" CommandName="UpdateEdited"   ToolTip ="Save Changes"                Visible='<%# rgvSecurityGroups.EditIndexes.Count > 0 or rgvSecurityGroups.MasterTableView.IsItemInserted%>'><asp:Image runat="server" CssClass="css_GFS01_Image_Align" ImageURL="<%$ Resources:Images,SaveRecord20%>" />  Update </asp:LinkButton>  
                        <asp:LinkButton ID="ibtSettings"     runat="server" CommandName="ShowSettings"   ToolTip ="Edit/View Security Settings" Visible='<%# rgvSecurityGroups.EditIndexes.Count=0 AND Not rgvSecurityGroups.MasterTableView.IsItemInserted%>'><asp:Image ID="Image1" runat="server" CssClass="css_GFS01_Image_Align" ImageURL="<%$ Resources:Images,SecuritySettings20%>" /> Security Settings  </asp:LinkButton>  
                        <asp:LinkButton ID="lbtRefresh"      runat="server" CommandName="RebindGrid"     ><asp:Image id="imgRefresh" runat="server" CssClass="css_GFS01_Image_Align" ImageURL="<%$Resources:Images, ReloadBlue16 %>" AlternateText ="Refresh Grid" /></asp:LinkButton>                     
                    </div>
                </CommandItemTemplate>
                <Columns>
                    <telerik:GridBoundColumn DataField="SecurityId"     UniqueName="SecurityID"     HeaderText="Security Id"        HeaderStyle-HorizontalAlign="Left"     HeaderStyle-Width="80px"    ItemStyle-HorizontalAlign="Center"  DataType="System.Int32" ReadOnly="true" />
                    <telerik:GridBoundColumn DataField="SecurityGroup"  UniqueName="SecurityGroup"  HeaderText="Group"              HeaderStyle-HorizontalAlign="Left"     HeaderStyle-Width="200px"   ColumnEditorID ="gtcEditor1"/>
                    <telerik:GridBoundColumn DataField="UserCount"      UniqueName="UserCount"      HeaderText="User Count"         HeaderStyle-HorizontalAlign="Left"     HeaderStyle-Width="80px"    ItemStyle-HorizontalAlign="Center"  DataType="System.Int32" ReadOnly="true" />
                    <telerik:GridBoundColumn DataField="CreatedBy"      UniqueName="CreatedBy"      HeaderText="Created By"         HeaderStyle-HorizontalAlign="Left"     HeaderStyle-Width="130px"   ItemStyle-HorizontalAlign="Left"    ReadOnly="true"  />
                    <telerik:GridBoundColumn DataField="CreatedDate"    UniqueName="CreatedDate"    HeaderText="Created Date"       HeaderStyle-HorizontalAlign="Center"   HeaderStyle-Width="130px"   ItemStyle-HorizontalAlign="Center"  DataType="System.DateTime" DataFormatString="{0:MM/dd/yy h:mm:ss t}"   ReadOnly="true" />
                    <telerik:GridBoundColumn DataField="UpdatedBy"      UniqueName="UpdatedBy"      HeaderText="Updated By"         HeaderStyle-HorizontalAlign="Left"     HeaderStyle-Width="130px"   ItemStyle-HorizontalAlign="Left"    ReadOnly="true" />
                    <telerik:GridBoundColumn DataField="UpdatedDate"    UniqueName="UpdatedDate"    HeaderText="Updated Date"       HeaderStyle-HorizontalAlign="Center"   HeaderStyle-Width="130px"   ItemStyle-HorizontalAlign="Center"  DataType="System.DateTime" DataFormatString="{0:MM/dd/yy h:mm:ss t}" ReadOnly="true" />                           
                </Columns>    
                <DetailTables>
                    <telerik:GridTableView   DataKeyNames="SecurityObject" >
                        <Columns>
                            <telerik:GridBoundColumn DataField="UserId"          UniqueName="UserID"         HeaderText="User Id"           HeaderStyle-HorizontalAlign="Left"     HeaderStyle-Width="50px"    ItemStyle-HorizontalAlign="Center"  ReadOnly="true" DataType="System.Int32"  />
                            <telerik:GridBoundColumn DataField="UserName"        UniqueName="UserName"       HeaderText="User Name"         HeaderStyle-HorizontalAlign="Left"     HeaderStyle-Width="150px"   />
                            <telerik:GridBoundColumn DataField="SecurityObject"  UniqueName="SecurityObject" HeaderText="Security Object"   HeaderStyle-HorizontalAlign="Left"     HeaderStyle-Width="150px"  DataType="System.Int32"  />
                            <telerik:GridBoundColumn DataField="UserLoginId"     UniqueName="UserLoginId"    HeaderText="Login Id"          HeaderStyle-HorizontalAlign="Left"     HeaderStyle-Width="150px"   />
                            <telerik:GridBoundColumn DataField="UserStatus"      UniqueName="UserStatus"     HeaderText="Status" />
                            <telerik:GridBoundColumn DataField="EmployeeStatus"  UniqueName="EmployeeStatus" HeaderText="Employee Status" />
                        </Columns>
                    </telerik:GridTableView>
                </DetailTables>                
            </MasterTableView>
        </telerik:RadGrid>
        <telerik:GridTextBoxColumnEditor ID="gtcEditor1" runat="server" TextBoxStyle-Width="200px" />     
        <telerik:RadWindowManager ID="rwmMessageBox" runat="server" Behaviors="Close, Move"  EnableViewState ="false" Animation="Slide" AnimationDuration="5"  Height="400" Width = "400" VisibleOnPageLoad ="true" DestroyOnClose="true"  Modal="true"   EnableEmbeddedSkins="true" Skin="Black" />
        <telerik:RadWindowManager ID="rwmSecuritySettings" runat="server" Behaviors="Close, Move"  EnableViewState ="false" Animation="Slide" AnimationDuration="5"  Height="700" Width = "835" VisibleOnPageLoad ="true" DestroyOnClose="true"  Modal="true"  Style="z-index:3000"  />
        <br />
    </asp:Panel>
</asp:panel
<asp:Panel ID="pnlFooter" runat="server" CssClass="css_GPC01_Panel_Footer">
        <asp:Label ID="lblObjectId"              runat="server"  CssClass="css_GPC01_Label_Tiny" />
</asp:Panel>
</asp:Content>
Private Sub rgvSecurityGroups_DetailTableDataBind(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridDetailTableDataBindEventArgs) Handles rgvSecurityGroups.DetailTableDataBind
       Dim SelectedRow As GridDataItem = CType(e.DetailTableView.ParentItem, GridDataItem)
       Dim intSecurityObject As Int32 = SelectedRow.GetDataKeyValue("SecurityID")
       SQLDS_SecurityGroupUsers.SelectParameters.Clear()
       SQLDS_SecurityGroupUsers.SelectParameters.Add("intObjectId", Convert.ToInt32(intSecurityObject))
       e.DetailTableView.DataSourceID = "SQLDS_SecurityGroupUsers"
   End Sub

4 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 16 Feb 2011, 09:58 AM
Hello Tracy,

You should be using either detail table binding using DataSourceID and declarative relations, or binding through the DetailTableDataBind event. Mixing the 2 approaches is not supported. In your code, you are using the DetailTableDataBind event handler to set a DataSourceID for the detail table. You need to set the DataSource property of the control directly.

Veli
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Tracy
Top achievements
Rank 1
answered on 16 Feb 2011, 11:12 PM
Hi Veli,

Thank you for your response.  I understand what you are saying the problem is but am not sure how to fix it in my scenario.  I have read through the documentation and looked at the demos for both types of databinding.  The problem is that all the documentation/demos are using select statements as the datasource, in my project the datasources will always be existing stored procedures.

The one issue with using stored procedures and assingning select parameters to them is that the field names have to match exactly.  Since I am using existing stored procedures I don't have the option of changing the stored procedure parameter names, therefore I create/pass the parameters dynamically to the procedure, as listed below. 
SQLDS_SecurityGroupUsers.SelectParameters.Clear()
SQLDS_SecurityGroupUsers.SelectParameters.Add("intObjectId", Convert.ToInt32(intSecurityObject))

I have been able to use this method successfully  so far, but your response tells me that I cannot use this approach in this scenario.

In order to achieve a master/details grid and use stored procedures as the datasources I have had to create a grid and use the NestedViewTemplate to hold the detail grid.  I then assign the parameter needed for the detail grid when the master grid is expanded.  Although this works, it seems like it is the long way around creating a master/details grid.

Is there a way to use the <DetailTables> option in the grid and use a stored procedure as the datasource and assign the parameters of the stored procedure dynamically?   I would guess that many people are using stored procedures that alreay exist in their databases rather than inline select statements.

Thank you for your time.

0
Accepted
Veli
Telerik team
answered on 17 Feb 2011, 01:36 PM
Hello Tracy,

On the contrary, you CAN use stored procedures with SqlDataSource controls. But you need to specify the DataSourceID of the detail table right in the markup. Thus, RadGrid will setup hierarchy binding with data source controls. If you have ParentTableRelations properly set for your detail table, RadGrid will try to pass the parameters to the object data source automatically. This is the approach described in the Hierarchical Data-Binding Using Declarative DataSource Controls help topic.

If this is not an option for you, you can still you DataSource controls to fetch the data, but you should not specify the DataSourceID of the detail table. You effectively take the approach with the DetailTableDataBind event, you set the DataSource of the detail table to the DataSource control instance itself, not the DataSourceID:

Private Sub rgvSecurityGroups_DetailTableDataBind(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridDetailTableDataBindEventArgs) Handles rgvSecurityGroups.DetailTableDataBind
       Dim SelectedRow As GridDataItem = CType(e.DetailTableView.ParentItem, GridDataItem)
       Dim intSecurityObject As Int32 = SelectedRow.GetDataKeyValue("SecurityID")
       SQLDS_SecurityGroupUsers.SelectParameters.Clear()
       SQLDS_SecurityGroupUsers.SelectParameters.Add("intObjectId", Convert.ToInt32(intSecurityObject))
       'set the DataSource to the DataSource control directly
       e.DetailTableView.DataSource = SQLDS_SecurityGroupUsers
   End Sub

If this does not work, try to explicitly call the Select() method of the DataSource control and assign the result to the detail table's DataSource property.

Veli
the Telerik team
0
Tracy
Top achievements
Rank 1
answered on 17 Feb 2011, 10:08 PM
Thank you Veli, this worked.
Tags
Grid
Asked by
Tracy
Top achievements
Rank 1
Answers by
Veli
Telerik team
Tracy
Top achievements
Rank 1
Share this question
or