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

[Solved] Paging with checkbox (selecting items) issues

2 Answers 122 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Darren Brink
Top achievements
Rank 1
Darren Brink asked on 15 Jan 2010, 01:30 PM
I recently inherited an application from a contractor for my company and there seems to be an issue with desired output that is returned.  In this part of the application the user searches for a group of addresses that they want to print labels for.  When the search results are returned the user can either print all labels or select which labels they want to print if they don't want/need to print all the labels. 

The issue I'm running into is this, the current page size for the data returned in 300 rows per page.  In the one instance that was reported there are a total of 500 records returned and when the user selects to go to the second page (no records selected on the first page) and they scroll down to the bottom of the second page and select the last 4 records to print when the mail merge takes place and the items are displayed to the user it shows 4 numerically sequential items from the first page (i.e. if the last for records are index id's 200 - 204 on the second page it returns the indexes from page 1 with those id's).  So rather than grab what was selected it returns the records from the first page with the same index id.  Is there anyway around this or to have the index not reset and start at the index of 0 each time a new page is selected?

See below for the code I'm looking into:

(aspx)

    <telerik:RadAjaxPanel LoadingPanelID="RadAjaxLoadingPanel1" runat="server" ID="upprint"
        <center> 
            <asp:HyperLink runat="server" Visible="false" ID="lnkopen" Text="Printing Complete, Click Here to open the document"></asp:HyperLink> 
        </center> 
 
        <!--Hidden Panel used for Exporting to Excel, all address information is stored in its own column with the export.--> 
        <telerik:RadGrid PageSize="300" AllowPaging="True"  
            EnableViewState="true"  
            AllowMultiRowSelection="true"  
            ID="rgLabels"  
            OnNeedDataSource="rgLabelsNDS"  
            runat="server"  
            AllowSorting="True"  
            AutoGenerateColumns="False"  
            GridLines="None"
            <MasterTableView CommandItemDisplay="Top" DataKeyNames="EventHeaderNumber"
                <CommandItemTemplate> 
                    <div class="header"
                        <asp:Button CssClass="Button" runat="server" onclick="PrintLabels" Text="Print Selected Labels" /> <asp:Button ID="Button1" CssClass="Button" runat="server" onclick="PrintAllLabels" Text="Print All Labels" /> 
                    </div> 
                </CommandItemTemplate> 
                <Columns> 
                    <telerik:GridClientSelectColumn></telerik:GridClientSelectColumn> 
                    <telerik:GridHyperLinkColumn Visible="false"  DataTextField="CounterId" HeaderText="Counter" UniqueName="column"></telerik:GridHyperLinkColumn> 
                    <telerik:GridBoundColumn DataField="CheckNumber" Visible="false" HeaderText="Check #" UniqueName="column1"></telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="ContactMailToFirstName" HeaderText="First" UniqueName="column11"></telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="ContactMailToLastName" HeaderText="Last" UniqueName="column12"></telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="EntityMailToEntityName" HeaderText="Company" UniqueName="column112"></telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="EntityMailToAddressStreet1" HeaderText="Add 1" UniqueName="column13"></telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="EntityMailToAddressStreet2" HeaderText="Add 2" UniqueName="column14"></telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="EntityMailToCity" HeaderText="City" UniqueName="column15"></telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="EntityMailToState" HeaderText="State" UniqueName="column16"></telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="EntityMailToPostalCode" HeaderText="Zip" UniqueName="column17"></telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="EntityMailToCountry" HeaderText="Cntry" UniqueName="column18"></telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="EntityId" Visible="true" HeaderText="ID" UniqueName="column19"></telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="EventHeaderNumber" Visible="true" HeaderText="Evt. #" UniqueName="column1944"></telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="HoldReason" Visible="false" HeaderText="Serial #" UniqueName="column20"></telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="EventProfileName" Visible="false" HeaderText="Exp. Date" UniqueName="column21"></telerik:GridBoundColumn> 
                </Columns> 
            </MasterTableView> 
            <ClientSettings> 
                <Selecting AllowRowSelect="True" /> 
            </ClientSettings> 
            <ExportSettings ExportOnlyData="true" IgnorePaging="true" Csv-FileExtension="csv" Csv-ColumnDelimiter="Tab" OpenInNewWindow="true"></ExportSettings> 
        </telerik:RadGrid> 
        <asp:HiddenField runat="server" ID="hdnsrch" /> 
    </telerik:RadAjaxPanel> 

(cs)
    public void PrintLabels(object sender, EventArgs e) 
    { 
            rbt_vw_EventHeaderProfileRow[] rows = new rbt_vw_EventHeaderProfileRow[rgLabels.SelectedItems.Count]; 
            int i = 0; 
            foreach (GridDataItem item in rgLabels.SelectedItems) 
            { 
                rows[i] = ((rbt_vw_EventHeaderProfileRow[])Session["LabelRows"])[item.ItemIndex]; 
                i++; 
            } 
 
            PrintLabel lbl = new PrintLabel(); 
            lnkopen.NavigateUrl = lbl.PrintLabels(rows, rdLabelType.SelectedItem.Text.ToLower(), "30"); 
            lnkopen.Visible = true
    } 

Any help would be appreciated.

2 Answers, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 21 Jan 2010, 09:22 AM
Hi Darren,

The value in ItemIndex property of each GridDataItem are calculated per page. So in each page the ItemIndex of item represents first row is 0. Note that the first item has index 0 not 1.
In the code you sent us I see that you hold all items in all pages in the collection into the Session object.  In order to get right Items from the Session you need to calculate the indexes of selected items, when the user click PrintLabels button. For each selected item:  
int itemNumber = rgLabels.PageSize * rgLabels.CurrentPageIndex + item.ItemIndex;

So in your case you need to change the PrintLabels event handler to:
protected void PrintLabels(object sender, EventArgs e)
{
   rbt_vw_EventHeaderProfileRow[] rows = new rbt_vw_EventHeaderProfileRow[rgLabels.SelectedItems.Count];
   int i = 0;
   foreach (GridDataItem item in rgLabels.SelectedItems)
   {
     int itemNumber = rgLabels.PageSize * rgLabels.CurrentPageIndex +
        item.ItemIndex;
     rows[i] = ((rbt_vw_EventHeaderProfileRow[])Session["LabelRows"])[itemNumber];
     i++;
   }
 
   PrintLabel lbl = new PrintLabel();
   lnkopen.NavigateUrl = lbl.PrintLabels(rows,
        rdLabelType.SelectedItem.Text.ToLower(), "30");
   lnkopen.Visible = true;
}

I hope this helps.

Best wishes,
Radoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Darren Brink
Top achievements
Rank 1
answered on 21 Jan 2010, 01:00 PM
I was actually able to accomplish what I needed by changing out the .itemIndex for dataItemIndex.

Thanks for the help,
Tags
Grid
Asked by
Darren Brink
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Darren Brink
Top achievements
Rank 1
Share this question
or