设计:有“标题”和“内容”两项,第一次进入,不显示“内容”。然后点击“标题”可以展开和收缩“内容”。
第一只:
.aspx 文件
<ItemTemplate>
<span class="date">
<asp:Button ID="BtnContent" Font-Bold='<%# GetBoldFlag(DataBinder.Eval(((RepeaterItem)Container).DataItem,"ID").ToString())%>' Runat = "server" Height=16 BackColor=LightCyan CssClass="HomeEntryTitle" Text = '<%# DataBinder.Eval(((RepeaterItem)Container).DataItem,"Title") %>' BorderStyle=none CommandArgument='<%# DataBinder.Eval(((RepeaterItem)Container).DataItem,"EntryName").ToString()%>'>
</asp:Button>
</span>
<asp:Literal runat = "server" Visible= '<%# isVial(DataBinder.Eval(((RepeaterItem)Container).DataItem,"EntryName").ToString())%>' Text ='<%# DataBinder.Eval(((RepeaterItem)Container).DataItem,"Description").ToString() %>' ID='DescriLit'>
</asp:Literal>
</ItemTemplate>
</asp:repeater>
.cs有两个函数:
private void RecentPosts_ItemCommand(object source, System.Web.UI.WebControls.RepeaterCommandEventArgs e)
{
entryName = e.CommandArgument.ToString().Trim();
string A_entryName = ViewState["entryName"] as string;
if (A_entryName == null || A_entryName != entryName)
{
ViewState["entryName"] = entryName;
//帮函数的只能一个地方绑,注意拉!
}
else
{
ViewState["entryName"] = "ToClose";
}
BindContextPost();
}
protected bool isVial(string Arg)
{
if(ViewState["entryName"] != null)
{
entryName = ViewState["entryName"].ToString();
if(Arg.Trim() == entryName)
{
return true;
}
}
return false;
}
第二只:
.aspx 文件
<asp:Literal runat = "server" Visible= false Text ='<%# DataBinder.Eval(((RepeaterItem)Container).DataItem,"Description").ToString() %>' ID='DescriLit'>
.cs有一个函数:
private void RecentPosts_ItemCommand(object source, System.Web.UI.WebControls.RepeaterCommandEventArgs e)
{
bool open = (ViewState["IsOpen"] == null)?false:(bool)ViewState["IsOpen"];
e.Item.Controls[6].Visible = open;
ViewState["IsOpen"] = !open;
}
第三只:
.aspx 文件
<asp:Literal runat = "server" Visible= false Text ='<%# DataBinder.Eval(((RepeaterItem)Container).DataItem,"Description").ToString() %>' ID='DescriLit'>
.cs有一个函数:
private void RecentPosts_ItemCommand(object source, System.Web.UI.WebControls.RepeaterCommandEventArgs e)
{
e.Item.Controls[7].Visible = !e.Item.Controls[7].Visible;
}
看看,赫赫,repeated的展开可以如此简单!
但我现在碰到一个问题,repeated的展开后,不能自动定位到展开处,这也是服务器端刷新的老问题了,可小弟我想了几种办法,用锚、websevice感觉都不好,请教有经验者,这是怎么做的。