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

Change the pagesizecombo and make the pager always visiible only when the record is greater than 10

4 Answers 71 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Uttam Dhakal
Top achievements
Rank 1
Uttam Dhakal asked on 02 Nov 2012, 01:15 AM




I have tried this function to implement the changes but the problem is
since it is a itemdatabound it will make lot of round trips to set this behaviour which is equal to number of the rows created i guess.
But this property has to be set at one time only. so is there a correct method or event that can make this thing happen with better performance rather than for each itemdatabound.

Also how to make the pager visible always when there are items more than 10.
now if i set it alwaysvisible = true then it displays the pager even there are no10 records.

I am looking a way to make the pager visible always only after 10. then even the page set is 100 and the rows present are 14 the pager should be still availiable so that user doesn't have to refresh the pager to see the default pager settings again.

Any help will be highly appreciated. Please....

protected
 void RadGrid1_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("15"));   
        PageSizeCombo.FindItemByText("15").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("150"));   
        PageSizeCombo.FindItemByText("150").Attributes.Add("ownerTableViewId", RadGrid1.MasterTableView.ClientID);   
        PageSizeCombo.Items.Add(new RadComboBoxItem("250"));   
        PageSizeCombo.FindItemByText("250").Attributes.Add("ownerTableViewId", RadGrid1.MasterTableView.ClientID);   
        PageSizeCombo.FindItemByText(e.Item.OwnerTableView.PageSize.ToString()).Selected = true
    } 

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 02 Nov 2012, 05:22 AM
Hi,

Please try the following code snippet to  make the pager visible when there are items more than 10 .

C#:
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
        int count = RadGrid1.MasterTableView.Items.Count;
        if (count <= 10)
        {
            RadGrid1.PagerStyle.Visible = false;
        }
        else
        {
            RadGrid1.PagerStyle.Visible = true;
        }
}

Thanks,
Princy.
0
Jayesh Goyani
Top achievements
Rank 2
answered on 02 Nov 2012, 05:33 AM
Hello,


Please check first code block below link
http://jayeshgoyani.blogspot.in/2012/06/customizing-items-of-radgrid-page-size.html

By using above code if your item count is 14 then it displayed : 10,14 in Page combo.

Thanks,
Jayesh Goyani
0
Uttam Dhakal
Top achievements
Rank 1
answered on 02 Nov 2012, 06:13 AM
Hi jayesh, i need to show 10,25,50,100.. In your code where do i assign these values.....
0
Jayesh Goyani
Top achievements
Rank 2
answered on 02 Nov 2012, 06:40 AM
Hello,

<telerik:RadGrid  ID="RadGrid1" runat="server" AutoGenerateColumns="False"
           OnNeedDataSource="RadGrid1_NeedDataSource" OnItemCreated="RadGrid1_ItemCreated"
 
           AllowPaging="true"
           PageSize="15">
           <MasterTableView DataKeyNames="ID" CommandItemDisplay="Top" EditMode="InPlace">
               <Columns>
                   <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
                   </telerik:GridBoundColumn>
                   <telerik:GridBoundColumn DataField="Name" UniqueName="Name" HeaderText="Name">
                   </telerik:GridBoundColumn>
                
                   <telerik:GridEditCommandColumn>
                   </telerik:GridEditCommandColumn>
               </Columns>
           </MasterTableView>
         
           <PagerStyle AlwaysVisible="true" />
       </telerik:RadGrid>
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
    {
 
        if (e.Item is GridEditableItem && e.Item.IsInEditMode)
        {
        }
 
        if (e.Item is GridPagerItem)
        {
            RadComboBox PageSizeCombo = (RadComboBox)e.Item.FindControl("PageSizeComboBox");
 
            PageSizeCombo.Items.Clear();
            PageSizeCombo.Items.Add(new RadComboBoxItem("15"));
            PageSizeCombo.FindItemByText("15").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("150"));
            PageSizeCombo.FindItemByText("150").Attributes.Add("ownerTableViewId", RadGrid1.MasterTableView.ClientID);
            PageSizeCombo.Items.Add(new RadComboBoxItem("250"));
            PageSizeCombo.FindItemByText("250").Attributes.Add("ownerTableViewId", RadGrid1.MasterTableView.ClientID);
            if (PageSizeCombo.FindItemByText(e.Item.OwnerTableView.PageSize.ToString()) != null)
            {
                PageSizeCombo.FindItemByText(e.Item.OwnerTableView.PageSize.ToString()).Selected = true;
            }
 
        }
 
    }
 
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        dynamic data = new[] {
            new { ID = 1, Name ="Name1",path="1.jpg",Customedate=DateTime.Now},
            new { ID = 2, Name = "Name2",path="2.jpg",Customedate=DateTime.Now},
            new { ID = 3, Name = "Name3",path="3.jpg",Customedate=DateTime.Now},
             new { ID = 4, Name = "Name4",path="2.jpg",Customedate=DateTime.Now},
            new { ID = 5, Name = "Name5",path="3.jpg",Customedate=DateTime.Now},
             new { ID = 6, Name ="Name1",path="1.jpg",Customedate=DateTime.Now},
            new { ID = 7, Name = "Name2",path="2.jpg",Customedate=DateTime.Now},
            new { ID = 8, Name = "Name3",path="3.jpg",Customedate=DateTime.Now},
             new { ID = 9, Name = "Name4",path="2.jpg",Customedate=DateTime.Now},
            new { ID = 10, Name = "Name5",path="3.jpg",Customedate=DateTime.Now},
             new { ID = 11, Name ="Name1",path="1.jpg",Customedate=DateTime.Now},
            new { ID = 12, Name = "Name2",path="2.jpg",Customedate=DateTime.Now},
            new { ID = 13, Name = "Name3",path="3.jpg",Customedate=DateTime.Now},
             new { ID = 14, Name = "Name4",path="2.jpg",Customedate=DateTime.Now},
            new { ID = 15, Name = "Name5",path="3.jpg",Customedate=DateTime.Now}
             
        };
        RadGrid1.DataSource = data;
    }

Please try with above demo and let me know it working or not

Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Uttam Dhakal
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Jayesh Goyani
Top achievements
Rank 2
Uttam Dhakal
Top achievements
Rank 1
Share this question
or