2012-08-07 97 views
0

我有一個手風琴,並在ContentTemplate中放置了下拉列表。 我正在使用Accordion1_ItemDataBound將數據表綁定到下拉列表。 主要問題是我無法找到下拉列表。FindControl手風琴內容ContentTemplate

<ContentTemplate> 
           <table border="0" width="490px" style="background-color: transparent"> 
            <tr> 
             <td> 
             </td> 
            </tr> 
            <tr> 
             <td align="right"> 
              <asp:TextBox runat="server" ID="txtNotes" TextMode="MultiLine" Height="100px" Width="200px"></asp:TextBox> 
             </td> 
             <td> 
              <asp:Label runat="server" ID="lbltest"></asp:Label> 
              <asp:DropDownList runat="server" ID="ddlStatus" Visible="true"> 
              </asp:DropDownList> 
             </td> 
             <td> 
              <asp:Button runat="server" ID="btnSubmit" Text="שמור נתונים" /> 
             </td> 
            </tr> 
           </table> 
           <%--<asp:Label ID="lblOrderID2" runat="server" Text='<%#Eval("MidaClient_ID")%>'></asp:Label>--%> 
           <%--<asp:Label ID="lblNotes" runat="server" Text='<%#Eval("Cand_Num")%>'></asp:Label>--%> 
           <%-- <asp:Button ID="btnSend" runat="server" Text="שלח" CommandName="send" />--%> 
          </ContentTemplate> 

protected void Accordion1_ItemDataBound(object sender, AjaxControlToolkit.AccordionItemEventArgs e) 
     { 
      if (e.ItemType != AjaxControlToolkit.AccordionItemType.Content) 
      { 
       DataTable dt = new DataTable(); 
       //dt = db.GetStatus(); 
       dt.Columns.Add(new DataColumn("OfferID", typeof(int))); 
       dt.Columns.Add(new DataColumn("TypeOffer", typeof(string))); 

       dt.Rows.Add(new object[] { 0, "First Row" }); 
       dt.Rows.Add(new object[] { 1, "Second Row" }); 
       if (dt != null) 
       { 
        DropDownList ddl = new DropDownList(); 
        ddl = (DropDownList)e.AccordionItem.FindControl("ddlStatus"); 
        if (ddl != null) 
        { 
         ClientScript.RegisterStartupScript(this.GetType(), "AlertBox", "alert('dropdownlist found');", true); 
        } 
        else 
        { 
         ClientScript.RegisterStartupScript(this.GetType(), "AlertBox", "alert('dropdownlist not found');", true); 
        } 
        //ddl.DataSource = dt; 
        //ddl.DataTextField = "Name"; 
        //ddl.DataValueField = "ID"; 
        //ddl.DataBind(); 
       } 
      } 


protected void LoadCandidates() 
{ 
    pds = new PagedDataSource(); 
    pds.DataSource = db.GetCandidates(456123, 6, "1037").DefaultView; 
    pds.AllowPaging = true; 
    pds.PageSize = 10; 
    if (SelectedPage > (pds.PageCount - 1)) 
     SelectedPage = pds.PageCount - 1; 
    if (SelectedPage < 0) 
    { 
     SelectedPage = 0; 
    } 
    pds.CurrentPageIndex = SelectedPage; 
    Accordion1.DataSource = pds; Accordion1.DataBind(); 
} 

回答

0

我注意到,你如果在這裏面查找調用語句:

if (e.ItemType != AjaxControlToolkit.AccordionItemType.Content) 

由於您的DDL是裏面的ContentTemplate也許陳述必須是:

if (e.ItemType == AjaxControlToolkit.AccordionItemType.Content) 
+0

如果我將它從!=更改爲==,然後它就沒有進入ID號 – Danny 2012-08-07 14:23:58

+0

你可以顯示你的代碼綁定到手風琴,它可以幫助診斷問題嗎? – bUKaneer 2012-08-07 14:35:47

+0

保護無效LoadCandidates() { PDS =新PagedDataSource(); pds.DataSource = db.GetCandidates(456123,6,「1037」)。DefaultView; pds.AllowPaging = true; pds.PageSize = 10; 如果(SelectedPage>(pds.PageCount - 1)) SelectedPage = pds.PageCount - 1; 如果(SelectedPage <0){ SelectedPage = 0; } pds.CurrentPageIndex = SelectedPage; Accordion1.DataSource = pds; Accordion1.DataBind(); } – Danny 2012-08-07 14:37:19