0
我创建显示文章的自定义页面,我添加了下拉列表,我可以选择排序顺序,并且还实现了自定义分页。 这里是代码保存下拉列表中的值
var sortOrder = new List<string> {"Title", "Date", "Author"};
if (!IsPostBack)
{
sortOrderDropDownList.DataSource = sortOrder;
sortOrderDropDownList.DataBind();
}
articles = articles.OrderBy(a => a.Heading).ToList();
if (IsPostBack)
{
switch (sortOrderDropDownList.SelectedItem.Value)
{
case "Date":
articles = articles.OrderByDescending(a => a.StartDate).ToList();
break;
case "Author":
articles = articles.OrderBy(a => a.AuthorComment).ToList();
break;
default:
articles = articles.OrderBy(a => a.Heading).ToList();
break;
}
}
this.ArticleRepeater.DataSource = articles;
if (articles.Count > 10)
{
int count = articles.Count - (number - 1) * 10 >= 10 ? 10 : articles.Count - (number - 1) * 10 - 1;
this.ArticleRepeater.DataSource = articles.GetRange((number - 1) * 10, count);
StringBuilder stringBuilder = new StringBuilder();
if (number > 1)
{
stringBuilder.AppendFormat("<a href='{0}?page={1} '>< Prev</a> | ", Request.Url.AbsolutePath, (number - 1));
stringBuilder.AppendFormat("<b>Page {0}</b>", number);
if (articles.Count > number * 10)
stringBuilder.AppendFormat(" | <a href='{0}?page={1}'>Next ></a>", Request.Url.AbsolutePath, (number + 1));
this.ArticlePaginator.Text = string.Format("<div class='ArticleListPagination'>{0}</div>", stringBuilder);
}
this.ArticleRepeater.DataBind();
}
我添加autoPostBack ='true'
向下拉菜单,然后wneh我从dropdown
选择,我的文章进行排序,但dropdown
选定值当我去到下一个页面(因为我创造不节省每次创建页面时都会下拉) 如何将dropdown
值保存到视图状态?我还在下拉菜单上设置了EnableViewState="True" ViewStateMode="Enabled"
谢谢! 你可以举一个例子如何做到这一点? –
请阅读以下内容:[cookies方式](http://www.codeproject.com/Articles/31914/Beginner-s-Guide-To-ASP-NET-Cookies),[session](http:// asp。 net-tutorials.com/state/sessions/) – gzaxx
非常感谢,希望它能帮助我 –