【发布时间】:2013-04-24 14:41:09
【问题描述】:
我正在使用中继器:
<asp:Repeater ID="rptCategories" runat="server" OnItemDataBound="RptCategories_ItemDataBound">
<ItemTemplate>
<asp:Panel CssClass="category-wrapper" ID="pnlCategory" runat="server">
<%# Eval("SponsorshipCategoryName") %>
<asp:HiddenField runat="server" ID="hdnCategoryID" Value='<%# Eval("SponsorshipCategoryID") %>' />
</asp:Panel>
</ItemTemplate>
</asp:Repeater>
根据我的类别类型,我将RadionButtonList 或复选框列表添加到后面代码的面板中。
我设置了id:
rblItems.ID = "rbl_" + category.SponsorshipCategoryID;
然后把控制权放在panel:
panel.Controls.Add(rblItems);
现在我需要能够遍历所有类别面板并获取那些单选按钮列表或复选框。
为此我循环rptCategories.Items
foreach (RepeaterItem rptItem in rptCategories.Items)
{
var hdnCategoryID = rptItem.FindControl(HdnCategoryID_ID) as
HiddenField;
var pnlCategory = rptItem.FindControl(PnlCategory_ID) as Panel;
var categoryID = (hdnCategoryID == null || hdnCategoryID.Value ==
string.Empty) ? 0 : int.Parse(hdnCategoryID.Value);
}
它找到隐藏字段和面板就好了。但是,当我试图在我的面板中找到具有我感兴趣的 ID 的控件时,它会返回 null。
var control = pnlCategory.FindControl("rbl_" + categoryToUpdate.SponsorshipCategoryID);
我不能在这里使用项目数据绑定事件。任何想法可能是什么问题?
【问题讨论】:
-
尝试添加 ClientIDMode="Static"