DESIGN: There are two items: "title" and "content". The first entry does not display "content ". Click "title" to expand and contract "content ".
First:
. Aspx File
<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 = 'scrilit'>
</Asp: Literal>
</ItemTemplate>
</Asp: repeater>
. Cs has two functions:
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;
// You can only bind the Helper function to one place. Please note that you can pull it!
}
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;
}
Second:
. Aspx File
<Asp: Literal runat = "server" Visible = false Text = '<% # DataBinder. eval (RepeaterItem) Container ). dataItem, "Description "). toString () %> 'id = 'scrilit'>
. Cs has a function:
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;
}
Third:
. Aspx File
<Asp: Literal runat = "server" Visible = false Text = '<% # DataBinder. eval (RepeaterItem) Container ). dataItem, "Description "). toString () %> 'id = 'scrilit'>
. Cs has a function:
Private void RecentPosts_ItemCommand (object source, System. Web. UI. WebControls. RepeaterCommandEventArgs e)
{
E. Item. Controls [7]. Visible =! E. Item. Controls [7]. Visible;
}
Look, the expansion of Hehe and repeated can be so simple!
However, I have encountered a problem. After the repeated is expanded, it cannot be automatically located at the expansion location. This is also an old problem for server refreshing. But I thought of several ways, it doesn't feel good to use an anchor or websevice. Ask experienced users how to do this.