从Repeater的FooterTemplate获取控制权

时间:2010-12-09 12:13:28

标签: c#

<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控件。

这不行,因为它不在ItmeTemplate中。

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

1 个答案:

答案 0 :(得分:3)

您需要使用ItemDataBound事件并在其中检查Footer。

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) {
                   ...
        }
    }
}