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

Rad Grid Filtering doesn't work when the page Size is more than 50

4 Answers 47 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kothai
Top achievements
Rank 1
Kothai asked on 19 Jul 2013, 06:03 AM
Hello,
Am using Rad Grid with NeedDataSource for databinding, and also used paging and filter.
I have set filtering only for "Contains" without filter icon just by pressing enter
Please find my aspx below,
I added paging drop down values in Grid_ItemCreated Event,
Filtering works fine when the page size is 50 or less than that,
Now my problem is when I select page size as 100, filtering is not working for any of the columns.

Using the browser Mozilla Firefox,


protected void Managegridview_ItemCreated(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridPagerItem)
            {
                var dropDown = (RadComboBox)e.Item.FindControl("PageSizeComboBox");
                var totalCount = ((GridPagerItem)e.Item).Paging.DataSourceCount;
                var sizes = new Dictionary<string, string>()
                {
            {"10", "10"},
            {"20", "20"},
            {"50", "50"}
                };
 
                if (totalCount > 100)
                {
                    sizes.Add("100", "100");
                }
                if (totalCount > 200)
                {
                    sizes.Add("200", "200");
                }
                sizes.Add("All", totalCount.ToString());
 
                dropDown.Items.Clear();
                foreach (var size in sizes)
                {
                    var cboItem = new RadComboBoxItem() { Text = size.Key, Value = size.Value };
                    cboItem.Attributes.Add("ownerTableViewId", e.Item.OwnerTableView.ClientID);
                    dropDown.Items.Add(cboItem);
                }
                
dropDown.FindItemByValue(e.Item.OwnerTableView.PageSize.ToString()).Selected = true;- NullreferenceException in this line(object reference not set to instance of object)
            }
        }

.aspx
<telerik:RadGrid ID="Managegridview" runat="server" AllowPaging="true" AllowSorting='true'
        GridLines="None" OnNeedDataSource="Managegridview_NeedDataSource" OnItemDataBound="Managegridview_ItemDataBound"
        AllowFilteringByColumn="true" CellSpacing="0" Skin="WebBlue"
        OnItemCreated="Managegridview_ItemCreated" PageSize="50">
        <GroupingSettings CaseSensitive="false"/>
        <ClientSettings EnableRowHoverStyle="true" AllowColumnsReorder="true" ReorderColumnsOnClient="true" AllowColumnHide="true" ColumnsReorderMethod="Reorder">
            <Resizing AllowColumnResize="true" AllowResizeToFit="true" ResizeGridOnColumnResize="false" />
            <Selecting AllowRowSelect="true" />
        </ClientSettings>
        <MasterTableView GridLines="None" Width="100%" AllowMultiColumnSorting="true">
            <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
            <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
            </RowIndicatorColumn>
            <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column"
                Created="True">
            </ExpandCollapseColumn>
            <EditFormSettings>
                <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                </EditColumn>
            </EditFormSettings>
            <PagerStyle PageSizeControlType="RadComboBox" Mode="NextPrevAndNumeric" EnableSEOPaging="True"
                AlwaysVisible="true"></PagerStyle>
        </MasterTableView>
        <HeaderStyle Width="100px" />
 
<%--<PagerStyle PageSizeControlType="RadComboBox"></PagerStyle>--%>
 
        <FilterMenu EnableImageSprites="False">
        </FilterMenu>
    </telerik:RadGrid>

4 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 19 Jul 2013, 09:34 AM
Hello,

Please try with the below code snippet.

protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridPagerItem)
        {
            var dropDown = (RadComboBox)e.Item.FindControl("PageSizeComboBox");
            var totalCount = ((GridPagerItem)e.Item).Paging.DataSourceCount;
            var sizes = new Dictionary<string, string>()
                {
            {"10", "10"},
            {"20", "20"},
            {"50", "50"}
                };
 
            if (totalCount > 100)
            {
                sizes.Add("100", "100");
            }
            if (totalCount > 200)
            {
                sizes.Add("200", "200");
            }
            sizes.Add("All", totalCount.ToString());
 
            if (sizes.Where(x => x.Key == e.Item.OwnerTableView.PageSize.ToString()).FirstOrDefault().Value == null)
            {
                sizes.Add(e.Item.OwnerTableView.PageSize.ToString(), e.Item.OwnerTableView.PageSize.ToString());
            }
 
            dropDown.Items.Clear();
            foreach (var size in sizes)
            {
                var cboItem = new RadComboBoxItem() { Text = size.Key, Value = size.Value };
                cboItem.Attributes.Add("ownerTableViewId", e.Item.OwnerTableView.ClientID);
                dropDown.Items.Add(cboItem);
            }
 
            dropDown.FindItemByValue(e.Item.OwnerTableView.PageSize.ToString()).Selected = true;
        }
    }



Thanks,
Jayesh Goyani
0
Kothai
Top achievements
Rank 1
answered on 19 Jul 2013, 10:00 AM
Hello Jayesh,

It works like a magic, Thank you, and i want to know whats the problem over there and What the below code does , why the pagesize of owner table view is null?

if (sizes.Where(x => x.Key == e.Item.OwnerTableView.PageSize.ToString()).FirstOrDefault().Value == null)
            {
                sizes.Add(e.Item.OwnerTableView.PageSize.ToString(), e.Item.OwnerTableView.PageSize.ToString());
            }

0
Princy
Top achievements
Rank 1
answered on 19 Jul 2013, 10:08 AM
Hi Kotai,

The error was occurring because after filtering the 'totalCount' will be less than 100. Since you are checking a condition to include 100 and 200 in ComboBox, after filtering(if the 'totalCount' is less than 100) 100 wont be added as a RadCombBox item in pager ComboBox. Please try the following condition to get rid of the error.

C#:
static bool Filter = false;
protected void Managegridview_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.FilterCommandName)
    {
        Filter = true;
    }
}
protected void Managegridview_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridPagerItem)
    {
        if (!Filter)
        {
            var dropDown = (RadComboBox)e.Item.FindControl("PageSizeComboBox");
            var totalCount = ((GridPagerItem)e.Item).Paging.DataSourceCount;
            var sizes = new Dictionary<string, string>()
                {
            {"10", "10"},
            {"20", "20"},
            {"50", "50"}
                };
            if (totalCount > 100)
            {
                sizes.Add("100", "100");
            }
            if (totalCount > 200)
            {
                sizes.Add("200", "200");
            }
            sizes.Add("All", totalCount.ToString());
            dropDown.Items.Clear();
            foreach (var size in sizes)
            {
                var cboItem = new RadComboBoxItem() { Text = size.Key, Value = size.Value };
                cboItem.Attributes.Add("ownerTableViewId", e.Item.OwnerTableView.ClientID);
                dropDown.Items.Add(cboItem);
            }
            dropDown.FindItemByValue(e.Item.OwnerTableView.PageSize.ToString()).Selected = true;
        }
    }           
}

Thanks,
Princy.
0
Kothai
Top achievements
Rank 1
answered on 19 Jul 2013, 10:24 AM
Hello Princy, Thank You.

Tags
Grid
Asked by
Kothai
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Kothai
Top achievements
Rank 1
Princy
Top achievements
Rank 1
Share this question
or