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

Customizing items in pagesize combobox

3 Answers 77 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Marja
Top achievements
Rank 1
Marja asked on 26 Nov 2013, 11:06 PM
I've subclassed the RadGrid to be able to provide a consistent, customized behavior for it in my web application.

Right now I'm trying to customize the pagesize combobox in the RadGrid, so it will display more options than the default.
The page size combobox correctly displays the new list of options, but selecting one of them does nothing. No event is fired and the grid contents is not updated.

What do I need to do to make it work?

My code:
Protected Overrides Sub OnItemCreated(e As Telerik.Web.UI.GridItemEventArgs)
 
    If TypeOf e.Item Is GridPagerItem Then
        Dim l_oPageSize As RadComboBox = DirectCast(e.Item.FindControl("PageSizeComboBox"), RadComboBox)
 
        l_oPageSize.Items.Clear()
 
        Dim l_oItem As RadComboBoxItem
        For l_iIndex As Integer = 10 To 150 Step 10
            l_oItem = New RadComboBoxItem(l_iIndex)
            l_oPageSize.Items.Add(l_oItem)
        Next
 
        l_oItem = New RadComboBoxItem(200)
        l_oPageSize.Items.Add(l_oItem)
        l_oItem = New RadComboBoxItem(300)
        l_oPageSize.Items.Add(l_oItem)
        l_oItem = New RadComboBoxItem(300)
        l_oPageSize.Items.Add(l_oItem)
        l_oItem = New RadComboBoxItem(350)
        l_oPageSize.Items.Add(l_oItem)
        l_oItem = New RadComboBoxItem(400)
        l_oPageSize.Items.Add(l_oItem)
        l_oItem = New RadComboBoxItem(450)
        l_oPageSize.Items.Add(l_oItem)
        l_oItem = New RadComboBoxItem(500)
        l_oPageSize.Items.Add(l_oItem)
        l_oItem = New RadComboBoxItem(600)
        l_oPageSize.Items.Add(l_oItem)
        l_oItem = New RadComboBoxItem(700)
        l_oPageSize.Items.Add(l_oItem)
        l_oItem = New RadComboBoxItem(800)
        l_oPageSize.Items.Add(l_oItem)
        l_oItem = New RadComboBoxItem(900)
        l_oPageSize.Items.Add(l_oItem)
        l_oItem = New RadComboBoxItem(1000)
        l_oPageSize.Items.Add(l_oItem)
 
        Dim l_iW As Integer = l_oPageSize.Width.ToString.Substring(0, l_oPageSize.Width.ToString.IndexOf("px"))
        l_oPageSize.Width = Unit.Pixel(l_iW + 10)
    End If
 
    MyBase.OnItemCreated(e)
End Sub

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 27 Nov 2013, 05:18 AM
Hi Marja,

Please modify the code as shown below .

VB:
If TypeOf e.Item Is GridPagerItem Then
    Dim l_oPageSize As RadComboBox = DirectCast(e.Item.FindControl("PageSizeComboBox"), RadComboBox)
    l_oPageSize.Items.Clear()
    Dim l_oItem As RadComboBoxItem = Nothing
    For l_iIndex As Integer = 10 To 150 Step 10
        l_oItem = New RadComboBoxItem(l_iIndex.ToString())
        l_oPageSize.Items.Add(l_oItem)
        l_oPageSize.FindItemByText(l_iIndex.ToString()).Attributes.Add("ownerTableViewId", RadGrid1.MasterTableView.ClientID)
    Next
   
    l_oItem = New RadComboBoxItem("200")
    l_oPageSize.Items.Add(l_oItem)
    l_oPageSize.FindItemByText("200").Attributes.Add("ownerTableViewId", RadGrid1.MasterTableView.ClientID)
   
    l_oItem = New RadComboBoxItem("300")
    l_oPageSize.Items.Add(l_oItem)
    l_oPageSize.FindItemByText("300").Attributes.Add("ownerTableViewId", RadGrid1.MasterTableView.ClientID)
    'Similarly for other page sizes
   
    l_oPageSize.FindItemByText(e.Item.OwnerTableView.PageSize.ToString()).Selected = True
  End If

Thanks,
Princy
0
Marja
Top achievements
Rank 1
answered on 27 Nov 2013, 09:47 AM
Hi Princy,

Thank you for you reply, but regretfully it doesn't make a difference.

Choosing another page size from the modified dropdown still does not cause the number of visible rows in the grid to change.
And as soon as I block my customization, the dropdown works correctly again.

So it seems that the default list of items can't be modified?
0
Accepted
Princy
Top achievements
Rank 2
answered on 27 Nov 2013, 10:00 AM
Hi Marja,

You can add PageSizes from the ASPX page as follows:

ASPX:
<PagerStyle Mode="NextPrevAndNumeric" PageSizeLabelText="Page Size: " PageSizes="5,10,25,50,100,250" />

or, Below is a sample code snippet that i tried to customize the PageSizes from code behind in the ItemCreated Event of the RadGrid:

VB:
Protected Sub RadGrid1_ItemCreated(sender As Object, e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemCreated
 If TypeOf e.Item Is GridPagerItem Then
   Dim PageSizeCombo As RadComboBox = DirectCast(e.Item.FindControl("PageSizeComboBox"), RadComboBox)
 
   PageSizeCombo.Items.Clear()
   PageSizeCombo.Items.Add(New RadComboBoxItem("10"))
   PageSizeCombo.FindItemByText("10").Attributes.Add("ownerTableViewId", RadGrid1.MasterTableView.ClientID)
   PageSizeCombo.Items.Add(New RadComboBoxItem("20"))
   PageSizeCombo.FindItemByText("20").Attributes.Add("ownerTableViewId", RadGrid1.MasterTableView.ClientID)
   PageSizeCombo.Items.Add(New RadComboBoxItem("50"))
   PageSizeCombo.FindItemByText("50").Attributes.Add("ownerTableViewId", RadGrid1.MasterTableView.ClientID)
   PageSizeCombo.Items.Add(New RadComboBoxItem("100"))
   PageSizeCombo.FindItemByText("100").Attributes.Add("ownerTableViewId", RadGrid1.MasterTableView.ClientID)
   PageSizeCombo.Items.Add(New RadComboBoxItem("200"))
   PageSizeCombo.FindItemByText("200").Attributes.Add("ownerTableViewId", RadGrid1.MasterTableView.ClientID)
   PageSizeCombo.FindItemByText(e.Item.OwnerTableView.PageSize.ToString()).Selected = True
   End If
End Sub

Thanks,
Princy
Tags
Grid
Asked by
Marja
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Marja
Top achievements
Rank 1
Share this question
or