gridview分页问题 [英] Problem with gridview Paging
问题描述
我使用linq to sql,并使用下拉列表显示记录,
我在.aspx文件中使用此代码进行分页
I use linq to sql,and use a drop down for showing records,
I use this code for paging in .aspx file
<asp:DropDownList ID="drpPageSize" class="form-control" runat="server" AutoPostBack="True" OnSelectedIndexChanged="drpPageSize_SelectedIndexChanged" meta:resourcekey="drpPageSizeResource1">
<asp:ListItem Selected="True" meta:resourcekey="ListItemResource1">5</asp:ListItem>
<asp:ListItem meta:resourcekey="ListItemResource2">10</asp:ListItem>
<asp:ListItem meta:resourcekey="ListItemResource10">50</asp:ListItem>
<asp:ListItem meta:resourcekey="ListItemResource12">100</asp:ListItem>
<asp:ListItem Text="All" meta:resourcekey="ListItemResource11"></asp:ListItem>
</asp:DropDownList>
并将此代码用于.cs文件,这里是gridbind和drpselect索引更改事件的代码
and use this code for .cs file,here is both code for gridbind and drpselect index changed event
protected void grdBind()
{
try
{
EventManagerDataContext db = new EventManagerDataContext();
var q = from a in db.EMR_EVENTs
join b in db.EMR_CLIENTs on a.ClientID equals b.ClientID
// join c in db.EMR_INVITATIONs on a.EventID equals c.EventID
select new
{
ClientName = b.Name,
ClientID = a.ClientID,
Name = a.Name,
No_Of_Invitees = a.No_Of_Invitees,
Extra_Invitees = a.Extra_Invitees,
Total_Invitees = a.Extra_Invitees + a.No_Of_Invitees,
EventID = a.EventID,
// InvitationId=c.InvitationID
};
grid.DataSource = q.ToList();
if (Convert.ToInt32(Session["k"])== 1)
{
grid.PageSize = Convert.ToInt32(Session["total"]); //here total is the no of rows in gridview
}
else
{
grid.PageSize = int.Parse(drpPageSize.SelectedValue);
}
grid.DataBind();
}
catch
{
throw;
}
}
protected void drpPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
if (drpPageSize.SelectedIndex == 4)
{
grid.AllowPaging = false;
Session["k"] = 1;
// grid.PageSize = Convert.ToInt32(Session["total"]);
grdBind();
}
else
{
Session["k"] = 2;
grid.PageSize = int.Parse(drpPageSize.SelectedItem.Text);
grdBind();
}
}
我的所有代码都正常工作。但是我发现当我从gridview中选择所有我发现所有记录时,但是从选择全部下拉后我选择5然后我没有得到5条记录,我得到了所有记录,与10,50,100相同>
请问任何解决方案。?
i也很欣赏我的要求更好的代码,我的主要目的是显示所有来自gridview的记录,当我从下拉列表中选择全部。
my all code is working. but i found that when i select all from gridview i found all records,but after select all from drop down i select 5 then i not get the 5 records ,insted of i get all the records,same as in 10,50,100
any solution please.?
i also appreciate that a better code for my requirement,my main purpose is show all records from gridview while i select all from dropdown.
推荐答案
在将会话设置为页面大小之前,尝试检查会话是否包含值。此外,建议使用下拉列表选择值而不是text.Carefully调试这些事情。
添加如何处理自定义分页的参考
http://devtoolbox.wordpress .com / tag / add-dropdown-list-to-pager / [ ^ ]
希望这有助于......
Try to check the session contains value before setting it as page size. Also, suggest to use the dropdownlist selected value instead of text.Carefully debug with these things in mind.
Adding a reference on how to deal with the custom pagination
http://devtoolbox.wordpress.com/tag/add-dropdown-list-to-pager/[^]
Hope this helps...
To允许在asp.net中使用gridview进行分页跟随...
gridview的设置属性是
To allow Paging in gridview in asp.net i used follow...
set property of gridview is
Allowpaging=True
pageSize=2 //(depend on you)
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
}
这篇关于gridview分页问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!