0

im trying to get numeric selection and a dropdown list(page size) at the bottom of a gridview. i can get the numerical selection to display using the pager settings OR the drop down list to be displayed using the pager template NOT both. They dont work together..

I found another with this problem here but no one supplied a valid answer.

the awful example below is the best i can provide (cannot post images)

,,,,,,gridview,,,,.

1 2 3 4 5 ,,,,,,,,,, page size |10|

EDIT forgot to add code

<PagerTemplate>
<div style="float:right;">
<span style="font-size: 13px; padding-left: 20px;">Records per page </span>
 <asp:DropDownList ID="ddlAmountDisplayed" runat="server" 
                        AutoPostBack="true">
 <asp:ListItem Selected="True" Value="25" Text="25"></asp:ListItem>
 <asp:ListItem Value="50" Text="50"></asp:ListItem>
 <asp:ListItem Value="75" Text="75"></asp:ListItem>
  <asp:ListItem Value="100" Text="100"></asp:ListItem>
 </asp:DropDownList>
  </div>
 </PagerTemplate>
 <PagerSettings Mode="NumericFirstLast"   Position="Bottom" />
Community
  • 1
  • 1
Nixdorf
  • 61
  • 8
  • i have found the answer to this, typically i found it a short time after posting the question, i will post the answer tomorrow (cannot answer within 8 hours) on the off chance it may help someone else as i have been stuck on this all day – Nixdorf Oct 01 '13 at 14:38

1 Answers1

1

As i said before, i found this site a short while after i posted the question, hopefully this will help someone else

 protected void AmountDisplayed_SelectedIndexChanged(object sender, EventArgs e)
    {
        DropDownList ddlPageSize = sender as DropDownList;
        if (ddlPageSize != null)
            this.gvCodes.PageSize = int.Parse(ddlPageSize.SelectedValue);

         if (ddlCodes.SelectedValue != "All" | ddlRegistered.SelectedValue != "All")
        {
            btnCodeSearch_Clicked(null, EventArgs.Empty);
        }
        else
        {
            BindCodes();
        }
        ddlPageSize.SelectedValue = this.gvCodes.PageSize.ToString();
    }

    protected void gvCodes_RowCreated(object sender, GridViewRowEventArgs e)
    {

        if (e.Row.RowType == DataControlRowType.Pager)
        {
            DropDownList ddlPageSize = new DropDownList();
            ddlPageSize.AutoPostBack = true;

            ddlPageSize.SelectedIndexChanged += new EventHandler(AmountDisplayed_SelectedIndexChanged);
            ddlPageSize.Items.Clear();
            int[] pageSizeOptions = new int[] { 25, 50, 75, 100 };

            for (int i = 0; i < pageSizeOptions.Length; i++)
            {
                ddlPageSize.Items.Add(pageSizeOptions[i].ToString());
            }

            Table pagerTable = e.Row.Cells[0].Controls[0] as Table;
            TableCell cell = new TableCell();
            cell.Controls.Add(new System.Web.UI.LiteralControl("Records per page:"));
            cell.Controls.Add(ddlPageSize);
            pagerTable.Rows[0].Cells.Add(cell);

            ddlPageSize.SelectedValue = this.gvCodes.PageSize.ToString();
        }
    }
Nixdorf
  • 61
  • 8