Controls added to placeholder in DetailsView nested in Gridview are not showing up
I'm trying to add a TextBox and a RequiredFieldValidator to the InsertItemTemplate of a DetailsView nested in a GridView. I added a PlaceHolder in the InsertItemTemplate, and I'm doing the following in the GridView's OnRowDataBound event:
if (e.Row.RowType == DataControlRowType.DataRow)
{
PlaceHolder vsPlaceHolder = (PlaceHolder)e.Row.FindControl("ValidationSummaryPlaceHolder");
ValidationSummary vs = new ValidationSummary();
vs.ID = "PickListValidationSummary" + e.Row.RowIndex;
vs.ValidationGroup = "PickListValidationGroup" + e.Row.RowIndex;
vs.CssClass = "failurenotification";
vsPlaceHolder.Controls.Add(vs);
DetailsView dv = (DetailsView)e.Row.FindControl("AddPickListOption");
PlaceHolder displayPlaceHolder = (PlaceHolder)dv.FindControl("DisplayTextPlaceHolder");
TextBox tb = new TextBox();
tb.ID = "txtDisplayText" + e.Row.RowIndex;
tb.Text = "<%# Bind(\"DisplayText\") %>";
RequiredFieldValidator rfv = new RequiredFieldValidator();
rfv.ID = "DisplayTextRequired" + e.Row.RowIndex;
rfv.ControlToValidate = tb1.ID;
rfv.ErrorMessage = "Enter text to display for the list option.";
rfv.ValidationGroup = "PickListValidationGroup" + e.Row.RowIndex;
rfv.ToolTip = "Enter text for the option";
rfv.Text = "*";
displayPlaceHolder.Controls.Add(tb1);
displayPlaceHolder.Controls.Add(rfv1);
}
The ValidationSummary is added to the placeholder fine (it's not in the DetailsView), but the TextBox and RequiredFieldValidator are not showing up in the PlaceHolder in the DetailsView InsertItemTemplate.
What am I missing here?
I'm trying to add a TextBox and a RequiredFieldValidator to the InsertItemTemplate of a DetailsView nested in a GridView. I added a PlaceHolder in the InsertItemTemplate, and I'm doing the following in the GridView's OnRowDataBound event:
if (e.Row.RowType == DataControlRowType.DataRow)
{
PlaceHolder vsPlaceHolder = (PlaceHolder)e.Row.FindControl("ValidationSummaryPlaceHolder");
ValidationSummary vs = new ValidationSummary();
vs.ID = "PickListValidationSummary" + e.Row.RowIndex;
vs.ValidationGroup = "PickListValidationGroup" + e.Row.RowIndex;
vs.CssClass = "failurenotification";
vsPlaceHolder.Controls.Add(vs);
DetailsView dv = (DetailsView)e.Row.FindControl("AddPickListOption");
PlaceHolder displayPlaceHolder = (PlaceHolder)dv.FindControl("DisplayTextPlaceHolder");
TextBox tb = new TextBox();
tb.ID = "txtDisplayText" + e.Row.RowIndex;
tb.Text = "<%# Bind(\"DisplayText\") %>";
RequiredFieldValidator rfv = new RequiredFieldValidator();
rfv.ID = "DisplayTextRequired" + e.Row.RowIndex;
rfv.ControlToValidate = tb1.ID;
rfv.ErrorMessage = "Enter text to display for the list option.";
rfv.ValidationGroup = "PickListValidationGroup" + e.Row.RowIndex;
rfv.ToolTip = "Enter text for the option";
rfv.Text = "*";
displayPlaceHolder.Controls.Add(tb1);
displayPlaceHolder.Controls.Add(rfv1);
}
The ValidationSummary is added to the placeholder fine (it's not in the DetailsView), but the TextBox and RequiredFieldValidator are not showing up in the PlaceHolder in the DetailsView InsertItemTemplate.
What am I missing here?
No comments:
Post a Comment