我在我的母版页上记录成员并在我的memberListing.aspx
上有这个代码<asp:Repeater ID="rptmembers" runar="server">
<ItemTemplate>
<div class="MemberName"><%# Eval("strName") %></div>
<div class="MemberSurname"><%# Eval("strSurname")%</div>
<ItemTemplate>
</asp:Repeater>
背后的代码
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
popMembers();
}
}
protected void popMembers()
{
DataTable dtMembers = clsmembers.GetMemberList();
StringBuilder sbMember = new StringBuilder();
rptmembers.DataSource = dtMembers;
rptmembers.DataBind();
}
这适用于显示数据库中的成员列表,但如何在会话中显示所有成员? ,通过在if语句周围包装....
if(clsMembers = (clsmembers)Session["clsmembers"] == dtMembers) //// some sort of check
{
// when show members in session with repeater
// when the session dies the member will not be shown in list till he logs back in
}
答案 0 :(得分:1)
如果您有一个存储在会话中的成员列表,将它绑定到转发器的最简单方法是:
BindingList<Member>
类型的变量,其中Member是具有strName和strSurname字段的类BindingList
绑定到转发器,例如。 rptMembers.DataSource = memeberBindingList
更简单的解决方案是在会话中存储BindingList,然后就足够了:
if(null != Session["clsMembers"])
{
rptmembers.DataSource = (BindingList<Member>)Session["clsMembers"];
rptmembers.DataBind();
}