我正在根据面板中的数据库值创建动态图形复选框。但当我尝试在单击全选复选框时更改选中状态。什么都没发生。我在里面找不到任何控件。
<%@ Register Assembly="EeekSoft.Web.Controls" Namespace="EeekSoft.Web.Controls" TagPrefix="cc1" %> <div style="overflow: auto; height: 462px; width: 386px; margin-top: 0px;">
<asp:Panel ID="optionPanel" runat="server" Height="479px" Width="380px">
<cc1:GraphicalCheckBox ID="chkSelectAll" runat="server" CheckedImg="images/checked.gif" OnCheckedChanged="chkSelectAll_CheckedChanged"
UncheckedImg="images/unchecked.gif" UncheckedOverImg="images/unchecked.gif" CheckedOverImg="images/checked.gif"
UncheckedDisImg="images/unchecked_disabled.gif" Style="cursor: hand;" Font-Size="100%" AutoPostBack="true"/>
<span class="survey_wizard_title" id="lblSelectAll" runat="server">Select All</span>
</asp:Panel>
</div>
`
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack && Request["SurveyID"] != null)
{
surveyID = Convert.ToInt32(Request["SurveyID"]);
PopulateParticipants();
}
}private void PopulateParticipants()
{foreach (OptionPool opt in respOptions)
{
Panel row = new Panel();
GraphicalCheckBox cb = new GraphicalCheckBox();
row.Attributes.Add("class", "surveyCheckbox");
cb.ID = Convert.ToString(opt.id);
cb.Attributes.Add("value", opt.id.ToString());
cb.Text = opt.data;
cb.Style.Add("cursor", "hand");
cb.Font.Size = new FontUnit("100%");
cb.UncheckedImg = "images/unchecked.gif";
cb.UncheckedOverImg = "images/unchecked.gif";
cb.CheckedImg = "images/checked.gif";
cb.CheckedOverImg = "images/checked.gif";
cb.UncheckedDisImg = "images/unchecked_disabled.gif";
row.Controls.Add(cb);
optionPanel.Controls.Add(row);
}}
protected void chkSelectAll_CheckedChanged(object sender, EventArgs e)
{
if (chkSelectAll.Checked == true)
{
foreach (Control child in optionPanel.Controls)
{
if (!(child is GraphicalCheckBox))
continue;
if ((child is GraphicalCheckBox))
{
(child as GraphicalCheckBox).Checked = true;
}
}
}
}
optionPanel.control不会列出上述任何动态创建的复选框。
答案 0 :(得分:0)
要在ASP.NET beetwen postbaks中使用动态控件,您需要使用Page_Init
方法重新创建它们,并且每次都使用相同的ID