2010-12-09 79 views
2
<FooterTemplate> 
    <tr> 
      <td class="menu"> 
      <a href="/Contact.aspx">Pomoč in podpora</a> 
      </td> 
    </tr> 
    <tr> 
      <td> 
      <asp:DropDownList ID="ddlChangeUser" runat="server" CssClass="childrenSelectType" AutoPostBack="True" Visible="false"     OnSelectedIndexChanged="ddlChangeUser_SelectedIndexChanged"> 
      </asp:DropDownList> 
      </td> 
    </tr> 

如何從中繼器的FooterTemplate獲取ddlChangeUser控件。從中繼器的FooterTemplate獲取控制

這不好,因爲它不在ItmeTemplate中。

DropDownList ddlChangeUser = siteMapAsBulletedList.Items[0].FindControl("ddlChangeUser") as DropDownList; 

回答

3

您需要使用ItemDataBound事件並在其中檢查頁腳。

siteMapAsBulletedList.ItemDataBound += new RepeaterItemEventHandler(siteMapAsBulletedList_ItemDataBound); 

... 

void siteMapAsBulletedList_ItemDataBound(object sender, RepeaterItemEventArgs e) 
{ 
    if (e.Item.ItemType == ListItemType.Footer) 
    { 
     DropDownList ddlChangeUser = (DropDownList)e.Item.FindControl("ddlChangeUser"); 
     if (ddlChangeUser != null) { 
        ... 
     } 
    } 
} 
+0

thx爲您的答案,但是沒有任何其他可能性從FooterTemplate獲取DropDownList? – senzacionale 2010-12-09 12:32:40