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

Trouble with OnClientSelectedIndexChanged in RadComboBox used for changing Grid's Page Size

1 Answer 157 Views
Grid
This is a migrated thread and some comments may be shown as answers.
chrbra
Top achievements
Rank 1
chrbra asked on 11 Oct 2011, 09:38 PM
Hi,

I am using RadControls for ASP.NET Ajax 2011 Q2.

I've got a RadGrid with paging enabled, and the page sizes can be changed. To achieve custom page sizes, I got this:

void RadGridView1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridPagerItem)
    {
        RadComboBox PageSizeCombo = (RadComboBox)e.Item.FindControl("PageSizeComboBox");
 
        PageSizeCombo.Items.Clear();
        PageSizeCombo.Items.Add(new RadComboBoxItem("25"));
        PageSizeCombo.FindItemByText("25").Attributes.Add("ownerTableViewId", RadGridView1.MasterTableView.ClientID);
        // and so on...

In the same aspx I have an overlay div which grays out the page and displays a waiting icon. It can be called via javascript, the code executing the overlay is simple and always works fine, because the elements both exist in every page:

function showLoadingOverlay() {
    try {
        $("#overlaydiv").css('visibility', 'visible');
        $(".loadingImage").css('visibility', 'visible');
    } catch (exc) { }
}
function hideLoadingOverlay() {
    try {
        $("#overlaydiv").css('visibility', 'hidden');
        $(".loadingImage").css('visibility', 'hidden');
    } catch (exc) { }
}


I use the RadComboBox'es OnClientSelectedIndexChanged Attribute on many ComboBoxes, that are Autopostback and do something time consuming, for this I have the function:

function OnClientSelectedIndexChanged(item) {
    showLoadingOverlay();
}


The trouble comes, when I set the OnClientSelectedIndexChanged method of the RadComboBox used for chaning page size, like this:

void RadGridView1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridPagerItem)
    {
        RadComboBox PageSizeCombo = (RadComboBox)e.Item.FindControl("PageSizeComboBox");
        PageSizeCombo.OnClientSelectedIndexChanged = "OnClientSelectedIndexChanged";
        // ...

The PageSizeCombo actually does display the overlay div as it should, BUT there is no PostBack.

Several other RadComboBoxes on the same page are AutoPostBack==true also, and they all still fire the PostBack even with theOnClientSelectedIndexChanged  event.

When I manually enable the AutoPostBack of the RadComboBox, there is a PostBack, but the RadGrid's NeedDataSource event isn't called (in which I use the new page size, if there is any).

void RadGridView1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridPagerItem)
    {
        RadComboBox PageSizeCombo = (RadComboBox)e.Item.FindControl("PageSizeComboBox");
        PageSizeCombo.OnClientSelectedIndexChanged = "OnClientSelectedIndexChanged";
        PageSizeCombo.AutoPostBack = true;


When I manually add a SelectedIndexChanged, that should refresh the data source (used by other RadComboBoxes!), the event still doesn't fire:

void RadGridView1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridPagerItem)
    {
        RadComboBox PageSizeCombo = (RadComboBox)e.Item.FindControl("PageSizeComboBox");
        PageSizeCombo.OnClientSelectedIndexChanged = "OnClientSelectedIndexChanged";
        PageSizeCombo.AutoPostBack = true;
        PageSizeCombo.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(FilterChanged_RadComboBox);

I really don't know what else to try, and I am wondering if this might be a bug, or at least something that doesn't work because nobody expected anyone to use the OnClientSelectedIndexChanged attribute of this builtin RadComboBox?

I would appriciate any fixed or workarounds, apart from creating my own RadComboBox for the pagesizes, because I don't want to fiddle with getting my own RadComboBox right next to the other paging controls.

Cheers

1 Answer, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 17 Oct 2011, 01:07 PM
Hi Avamboo_De,

You can use the following method, to fire your custom command which would get to the server, and allow you to rebind the control. In your case you should use fireCommand() client-side method inside OnClientSelectedIndexChanged client-side event to set the page size for the grid. Please refer to the help article below for more information:
http://www.telerik.com/help/aspnet-ajax/grid-gridtableview-set-pagesize.html

Best wishes,
Pavlina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
Grid
Asked by
chrbra
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Share this question
or