<option selected>12</option>
<option>15</option>
<option>20</option>
<option>30</option>
<option>50</option>
</select>
-------------------------------------------------------
<script type="text/javascript">
function UpdatePageSize() {
var $pageSize = $("#menuSelect").val();
window.location.href = "AccountManage.aspx?pageSize=" + $pageSize;
}
</script>
--------------------------------------------------------------
C#
string pageSizeStr = Request.QueryString["pageSize"];
int pageSize = 0;
FamilyAccountDataContext db = new FamilyAccountDataContext();
if (int.TryParse(pageSizeStr, out pageSize))
{
this.RepeaterAccount.DataSource = db.AccountTable.OrderByDescending(a => a.Date).Take(pageSize);
this.RepeaterAccount.DataBind();
this.menuSelect.Value = pageSize.ToString();
}
else
{
this.RepeaterAccount.DataSource = db.AccountTable.OrderByDescending(a => a.Date).Take(12);
this.RepeaterAccount.DataBind();
}
小结:利用jquery ajax 获取select option的值,然后重定向的该页面,并将select option值通过url传递,页面加载时获取这个值,实现数据重新绑定。回头来看很简单,但耗费了我好几个小时的时间解决。记录下来,希望能帮助需要的人。
使用jQuery AJAX与ASP.NET实现动态数据加载
本文详细介绍了如何结合jQuery AJAX和ASP.NET实现动态数据加载过程,包括前端获取下拉选项值、后端根据获取值进行数据筛选与绑定、以及URL参数传递等关键步骤。文章旨在提供一种简便、高效的数据加载方案,适用于网页应用中数据分页展示的需求。
1万+

被折叠的 条评论
为什么被折叠?



