我做了一个小演示来获得 selectedPane。在此窗格中访问 Controls 集合并找到相应的标签
public partial class demo : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
// init data, demo purposes
List<Person> liste = new List<Person>();
liste.Add(new Person() { ID = 0, Name = "jon0" });
liste.Add(new Person() { ID = 1, Name = "jon1" });
liste.Add(new Person() { ID = 2, Name = "jon2" });
liste.Add(new Person() { ID = 3, Name = "jon3" });
liste.Add(new Person() { ID = 4, Name = "jon4" });
Accordion1.DataSource = liste;
Accordion1.DataBind();
}
}
protected void btnGetName_Click(object sender, EventArgs e)
{
// get current pane by using Accordion1.SelectedIndex
Label lblName = Accordion1.Panes[Accordion1.SelectedIndex].FindControl("lblName") as Label;
Debug.WriteLine("Label: " + lblName.Text);
}
}
public class Person
{
public string Name { get; set; }
public int ID { get; set; }
}
这是我的aspx代码
<asp:Accordion ID="Accordion1" runat="server" SelectedIndex="0">
<HeaderTemplate>
<asp:Label ID="lblID" runat="server" Text='<%#"Pane" + Eval("ID") %>' />
<hr />
</HeaderTemplate>
<ContentTemplate>
<asp:Label ID="lblName" runat="server" Text='<%#Eval("Name") %>' />
<br />
<br />
</ContentTemplate>
</asp:Accordion>
<asp:Button ID="btnGetName" runat="server" Text="GetName" onclick="btnGetName_Click" />