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

PageSize and Page Index not working in the Detail Tables

2 Answers 65 Views
Grid
This is a migrated thread and some comments may be shown as answers.
illumination
Top achievements
Rank 2
illumination asked on 12 Oct 2010, 06:56 PM
Dear Forum User,
I am getting pretty frustrated on this issues with Page Indexing and Page Sizing in the Detail Tables. When I clicked the Page index or Page Size, then the grid just keep collapsing. Please see image. I'm not using NeedDataSource. I have tried detailtabledatabind, itemcommand, itemdatabound etc but still not working.
Please help me, it is urgent. (Trying to use the support ticket but I guess they are down since it keeps leading me to Error Page cannot be found).
This is my complete code:
<%@ Page Title="" Language="VB" MasterPageFile="~/Main.master" AutoEventWireup="false" CodeFile="AddFunding.aspx.vb" Inherits="AddFunding" %>
  
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
         
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" 
        Height="75px" Width="75px" InitialDelayTime="500" MinDisplayTime="250">
    </telerik:RadAjaxLoadingPanel>
      
    <telerik:RadAjaxManagerProxy ID="RadAjaxManagerProxy1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadGridFunding">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGridFunding" LoadingPanelID="RadAjaxLoadingPanel1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
</telerik:RadAjaxManagerProxy
  
    <h3>Line Item Details for PO #<span id="ponum" runat="server" ></span></h3>
<div>
<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" Width="100%" >   
<table>
    <tr>
        <td align="right">
        </td>
    </tr>
    <tr>
        <td>
            <telerik:RadGrid ID="RadGridFunding" runat="server" DataSourceID="SqlDsLineItem" 
                GridLines="None" AutoGenerateColumns="False" AllowPaging="True" PageSize="3" AllowMultiRowSelection="False" 
                AllowSorting="True" >
                <MasterTableView HierarchyDefaultExpanded="false" 
                    InsertItemPageIndexAction="ShowItemOnFirstPage" HierarchyLoadMode="Client" 
                    Name="Main" Width="100%" DataKeyNames="LineItemNumber" 
                    DataSourceID="SqlDsLineItem">
                    <DetailTables>
                        <telerik:GridTableView runat="server" HierarchyDefaultExpanded="false" CommandItemDisplay="Top" Name="Detail" AllowPaging="true" 
                            DataKeyNames="FundingID" DataSourceID="SqlDsFunding" AllowAutomaticUpdates="true" AllowAutomaticInserts="true" >
                            <ParentTableRelation>
                                <telerik:GridRelationFields DetailKeyField="LineItemNumber" MasterKeyField="LineItemNumber" />
                            </ParentTableRelation>
                            <RowIndicatorColumn>
                            <HeaderStyle Width="20px"></HeaderStyle>
                            </RowIndicatorColumn>
                            <ExpandCollapseColumn Visible="True">
                            <HeaderStyle Width="20px"></HeaderStyle>
                            </ExpandCollapseColumn>
                            <CommandItemSettings ExportToPdfText="Export to Pdf" />
                            <Columns>
                                <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn">
                                    <HeaderStyle Width="20px" />
                                </telerik:GridEditCommandColumn>
                                <telerik:GridTemplateColumn HeaderText="Funding Id" SortExpression="FundingId" UniqueName="FundingId" >
                                    <ItemTemplate>
                                        <asp:Label runat="server" ID="lblFundingId" Text='<%# Eval("FundingId") %>' ></asp:Label>
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridTemplateColumn HeaderText="Line Item Number" SortExpression="LineItemNumber" UniqueName="LineItemNumber" >
                                    <ItemTemplate>
                                        <asp:Label runat="server" ID="lblLineItemNumber" Text='<%# Eval("LineItemNumber") %>' ></asp:Label>
                                    </ItemTemplate>
                                    <EditItemTemplate>
                                        <span><telerik:RadTextBox runat="server" ID="txtRadLineItemNumber" Text='<%# Bind("LineItemNumber") %>' Width="100px" Skin="Default" ReadOnly="true" ></telerik:RadTextBox></span>
                                    </EditItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridDropDownColumn DataField="OperatingUnit" DataSourceID="SqlDsOpUnit"
                                    HeaderText="Operating Unit" ListTextField="operatingUnitId" ListValueField="operatingUnitId"
                                    UniqueName="OperatingUnit" >
                                </telerik:GridDropDownColumn>
                                <telerik:GridTemplateColumn HeaderText="Account Number" SortExpression="AccountNumber" UniqueName="AccountNumber" >
                                    <ItemTemplate>
                                        <asp:Label runat="server" ID="lblAccountNumber" Text='<%# Eval("AccountNumber") %>' ></asp:Label>
                                    </ItemTemplate>
                                    <EditItemTemplate>
                                        <span><telerik:RadTextBox runat="server" ID="txtRadAccountNumber" Text='<%# Bind("AccountNumber") %>' Width="100px" Skin="Default" ></telerik:RadTextBox></span>
                                    </EditItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridDropDownColumn DataField="Department" DataSourceID="SqlDsDept"
                                    HeaderText="Department" ListTextField="DepartmentId" ListValueField="DepartmentId"
                                    UniqueName="Department" >
                                </telerik:GridDropDownColumn>
                                <telerik:GridTemplateColumn HeaderText="Budget Reference" SortExpression="BudgetReference" UniqueName="BudgetReference" >
                                    <ItemTemplate>
                                        <asp:Label runat="server" ID="lblBudgetReference" Text='<%# Eval("BudgetReference") %>' ></asp:Label>
                                    </ItemTemplate>
                                    <EditItemTemplate>
                                        <span><telerik:RadTextBox runat="server" ID="txtRadBudgetReference" Text='<%# Bind("BudgetReference") %>' Width="100px" Skin="Default" ></telerik:RadTextBox></span>
                                    </EditItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridTemplateColumn HeaderText="Allocated Amount" SortExpression="AllocatedAmount" UniqueName="AllocatedAmount">
                                    <ItemTemplate>
                                        <asp:Label runat="server" ID="lblAllocatedAmount" Text='<%# Eval("AllocatedAmount", "{0:C}") %>'></asp:Label>
                                    </ItemTemplate>
                                    <EditItemTemplate>
                                        <span><telerik:RadNumericTextBox runat="server" ID="txtRadAllocatedAmount" DbValue='<%# Bind("AllocatedAmount") %>' Width="100px" Skin="Default" ></telerik:RadNumericTextBox>
                                        <span style="color: Red">
                                                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="txtRadAllocatedAmount"
                                                ErrorMessage="*" runat="server">
                                                </asp:RequiredFieldValidator></span>
                                    </EditItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridTemplateColumn HeaderText="" SortExpression="UpdatedDate" UniqueName="UpdatedDate" Visible="false" ReadOnly="true">
                                    <ItemTemplate>
                                        <asp:Label runat="server" ID="lblUpdatedDate" Text='<%# Eval("UpdatedDate", "{0:d}") %>' Visible="false" ></asp:Label>
                                    </ItemTemplate>
                                    <EditItemTemplate>
                                        <span><telerik:RadTextBox runat="server" ID="txtRadUpdatedDate" Text='<%# Bind("UpdatedDate") %>' Width="100px" Skin="Default" Visible="false" ReadOnly="true"></telerik:RadTextBox></span>
                                    </EditItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridTemplateColumn HeaderText="" SortExpression="UpdatedBy" UniqueName="UpdatedBy" Visible="false" ReadOnly="true">
                                    <ItemTemplate>
                                        <asp:Label runat="server" ID="lblUpdatedBy" Text='<%# Eval("UpdatedBy") %>' Visible="false" ></asp:Label>
                                    </ItemTemplate>
                                    <EditItemTemplate>
                                        <span><telerik:RadTextBox runat="server" ID="txtRadUpdatedBy" Text='<%# Bind("UpdatedBy") %>' Visible="false" ReadOnly="true"></telerik:RadTextBox></span>
                                    </EditItemTemplate>
                                </telerik:GridTemplateColumn>
                            </Columns>
                        <EditFormSettings>
                            <EditColumn ButtonType="ImageButton"/>
                        </EditFormSettings>
                        </telerik:GridTableView>
                    </DetailTables>
                    <RowIndicatorColumn>
                    <HeaderStyle Width="20px"></HeaderStyle>
                    </RowIndicatorColumn>
                    <CommandItemSettings ExportToPdfText="Export to Pdf" />
                    <ExpandCollapseColumn Visible="True">
                    <HeaderStyle Width="20px"></HeaderStyle>
                    </ExpandCollapseColumn>
                    <Columns>
                        <telerik:GridBoundColumn DataField="LineItemNumber" DataType="System.Int64" 
                            HeaderText="Line Item Number" SortExpression="LineItemNumber" 
                            UniqueName="LineItemNumber">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="PartName" HeaderText="Part Name" 
                            SortExpression="PartName" UniqueName="PartName">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="PartNumber" HeaderText="Part#" 
                            SortExpression="PartNumber" UniqueName="PartNumber">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="UnitPrice" DataType="System.Double" DataFormatString="{0:c}" 
                            HeaderText="Unit Price" SortExpression="UnitPrice" UniqueName="UnitPrice">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="QUANTITYORDERED" DataType="System.Int64" 
                            HeaderText="Qty Ordered" SortExpression="QUANTITYORDERED" 
                            UniqueName="QUANTITYORDERED">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="TotalCost" DataType="System.Double" DataFormatString="{0:c}" 
                            HeaderText="Total Cost" ReadOnly="True" SortExpression="TotalCost" 
                            UniqueName="TotalCost">
                        </telerik:GridBoundColumn>
                    </Columns>
                </MasterTableView>
                <ClientSettings AllowExpandCollapse="true" EnableRowHoverStyle="true">
                    <Selecting AllowRowSelect="True" />
                </ClientSettings>
            </telerik:RadGrid>
        </td>
    </tr>
</table>         
 
      
      
    <asp:SqlDataSource ID="SqlDsLineItem" runat="server" ConnectionString="<%$ ConnectionStrings:ServiceDeskConnectionString %>" 
        SelectCommand="SELECT [LineItemNumber], [PartName], [PartNumber], [UnitPrice], [QUANTITYORDERED], [TotalCost] FROM [vw_Funding] WHERE ([PONumber] = @PONumber) ORDER BY [LineItemNumber]">
        <SelectParameters>
            <asp:QueryStringParameter Name="PONumber" QueryStringField="id" Type="String" />
        </SelectParameters>
    </asp:SqlDataSource>
      
    <asp:SqlDataSource ID="SqlDsFunding" runat="server" ConnectionString="<%$ ConnectionStrings:ServiceDeskConnectionString %>" 
        SelectCommand="SELECT FundingId, LineItemNumber, OperatingUnit, AccountNumber, Department, BudgetReference, AllocatedAmount, InsertedDate, InsertedBy, UpdatedDate, UpdatedBy FROM PurchaseOrderFunding WHERE (LineItemNumber = @LineItemNumber) ORDER BY LineItemNumber" 
        DeleteCommand="DELETE FROM [PurchaseOrderFunding] WHERE [FundingId] = @FundingId" 
        InsertCommand="INSERT INTO PurchaseOrderFunding(LineItemNumber, OperatingUnit, AccountNumber, Department, BudgetReference, AllocatedAmount, InsertedDate, InsertedBy, UpdatedDate, UpdatedBy) VALUES (@LineItemNumber, @OperatingUnit, @AccountNumber, @Department, @BudgetReference, @AllocatedAmount, GETDATE(), @InsertedBy, GETDATE(), @UpdatedBy)" 
        UpdateCommand="UPDATE PurchaseOrderFunding SET LineItemNumber = @LineItemNumber, OperatingUnit = @OperatingUnit, AccountNumber = @AccountNumber, Department = @Department, BudgetReference = @BudgetReference, AllocatedAmount = @AllocatedAmount, UpdatedDate = GETDATE(), UpdatedBy = @UpdatedBy WHERE (FundingId = @FundingId)" >
        <SelectParameters>
            <asp:SessionParameter Name="LineItemNumber" SessionField="LineItemNumber" Type="Int32" />
        </SelectParameters>
        <DeleteParameters>
            <asp:Parameter Name="FundingId" Type="Int32" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="LineItemNumber" Type="Int32" />
            <asp:Parameter Name="OperatingUnit" Type="String" />
            <asp:Parameter Name="AccountNumber" Type="String" />
            <asp:Parameter Name="Department" Type="String" />
            <asp:Parameter Name="BudgetReference" Type="String" />
            <asp:Parameter Name="AllocatedAmount" Type="Decimal" />
            <asp:SessionParameter Name="UpdatedBy" Type="String" SessionField="UserName" />
            <asp:Parameter Name="FundingId" Type="Int32" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="LineItemNumber" Type="Int32" />
            <asp:Parameter Name="OperatingUnit" Type="String" />
            <asp:Parameter Name="AccountNumber" Type="String" />
            <asp:Parameter Name="Department" Type="String" />
            <asp:Parameter Name="BudgetReference" Type="String" />
            <asp:Parameter Name="AllocatedAmount" Type="Decimal" />
            <asp:SessionParameter Name="InsertedBy" Type="String" SessionField="UserName" />
            <asp:SessionParameter Name="UpdatedBy" Type="String" SessionField="UserName" />
        </InsertParameters>
        </asp:SqlDataSource>        
    <br />
    <asp:SqlDataSource ID="SqlDsOpUnit" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ServiceDeskConnectionString %>" 
        ProviderName="<%$ ConnectionStrings:ServiceDeskConnectionString.ProviderName %>" 
        SelectCommand="SELECT DISTINCT operatingUnitId FROM PurchaseOrderOperatingUnit ORDER BY operatingUnitId">
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="SqlDsDept" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ServiceDeskConnectionString %>" 
        SelectCommand="SELECT DISTINCT departmentId FROM PurchaseOrderDepartment ORDER BY departmentId">
    </asp:SqlDataSource>
</telerik:RadAjaxPanel>
</div>
  
</asp:Content>
  
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ponum.InnerHtml = Request.QueryString("id")
  
        If Not IsPostBack Then
            'Setting Selected index prior to binding RadGrid:
            'If the index is in detail table, parent items will be expanded
            'automatically 
            'RadGridFunding.SelectedIndexes.Add(1, 0, 1, 0, 1)
            'Index of 1, 0, 1, 0, 0 means:
            '1 - item with index 1 in MasterTableView
            '0 - detail table with index 0
            '1 - second (index 1) item in the detail table
            '0 - 0 sub-detail
            '1 - sub detail item with index 1
        End If
    End Sub
  
    Protected Sub RadGridFunding_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadGridFunding.PreRender
        If Not Page.IsPostBack Then
            RadGridFunding.MasterTableView.Items(0).Expanded = False
            'RadGridFunding.MasterTableView.Items(0).ChildItem.NestedTableViews(0).Items(0).Expanded = False
  
        End If
    End Sub
  
    Protected Sub RadGridFunding_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGridFunding.ItemDataBound
        If "Detail".Equals(e.Item.OwnerTableView.Name) Then
            If (TypeOf e.Item Is GridEditFormInsertItem) Then
                ' hide the control in insert mode
                If TypeOf e.Item Is GridEditFormInsertItem AndAlso e.Item.IsInEditMode Then
                    If e.Item.OwnerTableView.IsItemInserted Then
                        Dim edititem As GridEditFormInsertItem = DirectCast(e.Item, GridEditFormInsertItem)
                        edititem("LineItemNumber").Parent.Visible = False
                    End If
                End If
            End If
        End If
    End Sub
  
    Private Sub RadGridFunding_PageIndexChanged(ByVal source As Object, ByVal e As Telerik.Web.UI.GridPageChangedEventArgs) Handles RadGridFunding.PageIndexChanged
        RadGridFunding.Rebind()
        RadGridFunding.Visible = True
    End Sub
  
    Protected Sub RadGridFunding_PageSizeChanged(ByVal source As Object, ByVal e As Telerik.Web.UI.GridPageSizeChangedEventArgs) Handles RadGridFunding.PageSizeChanged
        RadGridFunding.Rebind()
        RadGridFunding.Visible = True
    End Sub
  
    Protected Sub RadGridFunding_ItemUpdated(ByVal source As Object, ByVal e As Telerik.Web.UI.GridUpdatedEventArgs) Handles RadGridFunding.ItemUpdated
        Dim item As String = getItemName(e.Item.OwnerTableView.Name)
        Dim field As String = getFieldName(e.Item.OwnerTableView.Name)
        If Not e.Exception Is Nothing Then
            e.KeepInEditMode = True
            e.ExceptionHandled = True
            DisplayMessage(" " + item + " " + e.Item(field).Text + " Data cannot be updated. Reason: " + e.Exception.Message)
        Else
            DisplayMessage(" " + item + " " + e.Item(field).Text + " Data has been successfully updated.")
        End If
    End Sub
  
    Protected Sub RadGridFunding_ItemInserted(ByVal source As Object, ByVal e As GridInsertedEventArgs) Handles RadGridFunding.ItemInserted
        Dim item As String = getItemName(e.Item.OwnerTableView.Name)
        Dim field As String = getFieldName(e.Item.OwnerTableView.Name)
        If Not e.Exception Is Nothing Then
            e.KeepInInsertMode = True
            e.ExceptionHandled = True
            DisplayMessage(" " + item + " " + e.Item(field).Text + " Data cannot be inserted. Reason: " + e.Exception.Message)
        Else
            DisplayMessage(" " + item + " " + e.Item(field).Text + " Data has been successfully inserted.")
        End If
    End Sub
  
    Protected Sub RadGridFunding_InsertCommand(ByVal source As Object, ByVal e As GridCommandEventArgs) Handles RadGridFunding.InsertCommand
       If "Detail".Equals(e.Item.OwnerTableView.Name) Then
            Dim parentItem As GridDataItem = DirectCast(e.Item.OwnerTableView.ParentItem, GridDataItem)
            SqlDsFunding.InsertParameters("LineItemNumber").DefaultValue = parentItem.OwnerTableView.DataKeyValues(parentItem.ItemIndex)("LineItemNumber").ToString()
        End If
    End Sub
  
    Private Function getItemName(ByVal tableName As String) As String
       Select Case tableName
            Case ("Main")
                Return "LineItemNumber"
            Case ("Detail")
                Return "LineItemNumber"
            Case Else
                Return ""
        End Select
    End Function
  
    Private Function getFieldName(ByVal tableName As String) As String
        Select Case tableName
            Case ("Main")
                Return "LineItemNumber"
            Case ("Detail")
                Return "LineItemNumber"
            Case Else
                Return ""
        End Select
    End Function
  
    Private Sub DisplayMessage(ByVal text As String)
        RadGridFunding.Controls.Add(New LiteralControl(String.Format("<span style='color:red'>{0}</span>", text)))
    End Sub
Thank you very much.

2 Answers, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 18 Oct 2010, 04:12 PM
Hello,

Can you please let me know as to why do you need to rebind RadGrid on PageIndexChanged and PageSizeChanged event? I'm asking this since this will cause RadGrid to collapse the expanded items.

Best regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
illumination
Top achievements
Rank 2
answered on 18 Oct 2010, 04:18 PM
Thank you for the response Daniel.
I fixed it by deleting PageIndexChanged and PageSizeChanged event. the older application used these events and not this version anymore which I found out.
So it is working now.
Thanks again.
Tags
Grid
Asked by
illumination
Top achievements
Rank 2
Answers by
Daniel
Telerik team
illumination
Top achievements
Rank 2
Share this question
or