Reputation: 11469
I have a GridView that was changed to a RadGrid, now before the GridView had the paging using a drop down above it with the following options to show items per page
<asp:DropDownList ID="lstPage" runat="server" AutoPostBack="true" OnSelectedIndexChanged="lstPage_OnSelectedIndexChanged">
<asp:ListItem Value="5">5</asp:ListItem>
<asp:ListItem Value="15" Selected="True">15</asp:ListItem>
<asp:ListItem Value="20">20</asp:ListItem>
<asp:ListItem Value="50">50</asp:ListItem>
</asp:DropDownList>
</div>
But now with the RadGrid I am not sure how to do that? and I cant find the specific example on their site. Is there a way to tell the rad grid to use those custom values? 10,35,60,100> I am required to show the same options in tha paging.
Thank you
Upvotes: 1
Views: 2493
Reputation: 11154
Method 1:
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;
}
}
Method 2:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
if (e.Item is GridPagerItem)
{
GridPagerItem pager = (GridPagerItem)e.Item;
RadComboBox PageSizeComboBox = (RadComboBox)pager.FindControl("PageSizeComboBox");
RadComboBoxItem ComboItem = new RadComboBoxItem("All");
PageSizeComboBox.Items.Insert(0, ComboItem);
PageSizeComboBox.AutoPostBack = true;
PageSizeComboBox.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(PageSizeComboBox_SelectedIndexChanged);
}
}
void PageSizeComboBox_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
//Handle the event
}
}
Upvotes: 2