标签:tput prot back obj duration drop eve hang tar
页面:
<%-- 缓存设置 --%>
<%@ OutputCache Duration="30" VaryByParam="none" %>
<asp:DropDownList ID="ddlType" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlType_SelectedIndexChanged" >
</asp:DropDownList>
</br>
<asp:Repeater ID="rtBooks" runat="server">
<ItemTemplate>
<a href="页面详情.aspx?id=<%#Eval("Id") %>"><%#Eval("Id") %>,<%#Eval("Title") %>,<%#Eval("Clicks") %></a><br></br>
</ItemTemplate>
</asp:Repeater>
后台:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) {
//加载图书数据
GetBooks();
//加载类型数据
GetBooksType();
}
}
//加载图书数据
void GetBooks() {
this.rtBooks.DataSource = new BooksManager().getAllBooksInfo().Take(10);
this.rtBooks.DataBind();
}
//加载类型数据
void GetBooksType() {
this.ddlType.DataSource = new CategoriesManager().getCategories();
ddlType.DataTextField = "Name";
ddlType.DataValueField = "Id";
this.ddlType.DataBind();
}
//下拉列表选择改变显示内容
protected void ddlType_SelectedIndexChanged(object sender, EventArgs e)
{
int id = Convert.ToInt32(ddlType.SelectedValue);
this.rtBooks.DataSource = new BooksManager().getAllBooksInfo().Where(m => m.CategoryId == id).Take(5).ToList();
this.rtBooks.DataBind();
}
标签:tput prot back obj duration drop eve hang tar
原文地址:http://www.cnblogs.com/pinkyZhou/p/7067851.html