2008-09-24 7 views

답변

0

더 섹시한 방법 일 수 있지만이 작동합니다. 원하는대로 데이터 소스를 채 웁니다. 이는 데모 용이었습니다. PrettyTitle() 키는 아코디언에 두 가지 항목 유형이 있음을 기억하는 것입니다.

<html xmlns="http://www.w3.org/1999/xhtml" > 
<head runat="server"> 
    <title>Accordion Binding</title> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <asp:ScriptManager ID="AjaxScriptManager" runat="server"> 
    </asp:ScriptManager> 
    <div> 
     <cc1:Accordion ID="AccordionControl" runat="server" 
      onitemdatabound="AccordionControl_ItemDataBound"> 
      <Panes></Panes> 
      <HeaderTemplate> 
       <asp:Label ID="HeaderLabel" runat="server" /> 
      </HeaderTemplate> 
      <ContentTemplate> 
       <asp:Literal ID="ContentLiteral" runat="server" /> 
       <asp:HyperLink ID="ContentLink" runat="server" /> 
      </ContentTemplate> 
     </cc1:Accordion><asp:xmldatasource runat="server" ID="RockNUGTwitter" ></asp:xmldatasource> 
    </div> 
    </form> 
</body> 

</html> 

그리고 숨김

은 다음과 같습니다

Using System; 
using System.Web.UI.WebControls; 
using System.Xml; 

namespace Ajaxy 
{ 
    public partial class _Default : System.Web.UI.Page 
    { 
     protected void Page_Load(object sender, EventArgs e) 
     { 
      Fill(); 
     } 

     private void Fill() 
     { 

      PopulateDataSource(); 
      AccordionControl.DataSource = RockNUGTwitter.GetXmlDocument().SelectNodes("//item"); 
      AccordionControl.DataBind(); 

     } 

     private void PopulateDataSource() 
     { 
      XmlDocument RockNugTwitterRSSDocument = new XmlDocument(); 
      RockNugTwitterRSSDocument.Load("http://twitter.com/statuses/user_timeline/15912811.rss"); 
      RockNUGTwitter.Data = RockNugTwitterRSSDocument.OuterXml; 
     } 

     protected void AccordionControl_ItemDataBound(object sender, AjaxControlToolkit.AccordionItemEventArgs e) 
     { 
      XmlNode ItemNode = (XmlNode)e.AccordionItem.DataItem; 
      if(e.AccordionItem.ItemType == AjaxControlToolkit.AccordionItemType.Content) 
      { 
       HyperLink ContentLink = (HyperLink)e.AccordionItem.FindControl("ContentLink"); 
       ContentLink.NavigateUrl = ItemNode.SelectSingleNode("link").InnerText; 
       Literal ContentLiteral = (Literal)e.AccordionItem.FindControl("ContentLiteral"); 
       ContentLiteral.Text = ItemNode.SelectSingleNode("title").InnerText; 
       ContentLink.Text = "Link"; 
      } 
      else if(e.AccordionItem.ItemType == AjaxControlToolkit.AccordionItemType.Header) 
      { 
       Label HeaderLabel = (Label) e.AccordionItem.FindControl("HeaderLabel"); 
       HeaderLabel.Text = PrettyTitle(ItemNode.SelectSingleNode("title").InnerText); 
      } 
     } 

     private string PrettyTitle(string FullItem) 
     { 
      string PrettyString = FullItem.Replace("RockNUG: ", ""); 
      string[] Words = PrettyString.Split(' '); 
      const int MAX_WORDS_TOSHOW = 4; 
      int WordsToShow = MAX_WORDS_TOSHOW; 
      if(Words.Length < MAX_WORDS_TOSHOW) 
      { 
       WordsToShow = Words.Length; 
      } 
      PrettyString = String.Join(" ", Words, 0, WordsToShow); 
      if (Words.Length > WordsToShow) 
      { 
       PrettyString += "..."; 
      } 
      return PrettyString; 
     } 
    } 
} 
관련 문제