我试图获取数字选择和gridview底部的下拉列表(页面大小)。我可以使用寻呼机设置显示数字选择,或使用寻呼机模板显示下拉列表,而不是两者。他们不在一起工作..
我发现了另一个问题here,但没有人提供有效答案。
以下可怕的例子是我能提供的最好的(无法发布图片)
,,,,,, gridview的,,,,。
1 2 3 4 5 ,,,,,,,,,,,页面大小| 10 |
EDIT 忘了添加代码
<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" />
答案 0 :(得分:1)
正如我之前所说,我在发布问题后不久发现了site,希望这会有助于其他人
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();
}
}