リピーターの RadioButtonList に RequiredFieldValidator を動的に追加しようとしていますが、次のエラーで失敗します。
Unable to find control id 'rblAccessory_40' referenced by the 'ControlToValidate' property of ''.
このセクションのコードは次のとおりです。
if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
{
Label lblAccID = (Label)e.Item.FindControl("lblAccID");
RadioButtonList rblCondition = (RadioButtonList)e.Item.FindControl("rblCondition");
rblCondition.ID = "rblAccessory_" + lblAccID.Text;
if (conditionList.Count() > 0)
{
RequiredFieldValidator rfv = new RequiredFieldValidator();
rfv.ControlToValidate = "rblAccessory_" + lblAccID.Text;
rfv.ErrorMessage = "Please complete the accessories section";
pnlValidation.Controls.Add(rfv);
rblCondition.DataSource = conditionList;
rblCondition.DataValueField = "id";
rblCondition.DataBind();
}
foreach (ListItem li in rblCondition.Items)
{
li.Text = "";
li.Value = "AccessoryID_" + lblAccID.Text + "-ConditionID_" + li.Value;
}
}
}
この時点でデータが正しくバインドされているため、RadioButtonList (rblCondition) が確実に見つかります。
rblCondition.DataSource = conditionList;
rblCondition.DataValueField = "id";
rblCondition.DataBind();
そのため、コントロール ID が見つからないというエラーが表示される理由がわかりません。
以下のように、コントロール ID を手動で指定しようとしました。
rfv.ControlToValidate = "rblAccessory_" + lblAccID.Text;
また、試しました:
rfv.ControlToValidate = rblCondition.ID;
lblAccID は、リピーターの行の ID を格納するために使用される非表示のテキスト フィールドです。