B
Brad Baker
I am trying to programmatically set a placeholder control in csharp which is
nested inside a repeater control between <ItemTemplate> and </ItemTemplate>
tags, however I am running into problems. I've tried several different
approaches for finding the placeholder:
This:
MyControl = this.FindControl("$form$tabs_repeater$PlaceHolder1");
Produces this error:
Object reference not set to an instance of an object.
This:
MyControl =
(PlaceHolder)tabs_repeater.Items[intSiteNum].FindControl("PlaceHolder1");
Produces this error:
Index was out of range. Must be non-negative and less than the size of the
collection. Parameter name: index
Below is an abbreviated excerpt of my code. Can anyone suggest what I might
be doing wrong?
Thanks,
Brad
protected string GenerateNavBarLink(string currentdepartmentid, int SiteNum)
{
int intSiteNum = SiteNum;
string strdepartmentid = currentdepartmentid;
LinkButton btn = new LinkButton();
btn.ID = "LinkButton1";
btn.Command += new_department_button_Click;
btn.Text = "Add Department +";
Control MyControl = new Control();
// Two different ways of updating the place holder
//MyControl =
this.FindControl("form$tabs_repeater$PlaceHolder1");
//MyControl =
(PlaceHolder)tabs_repeater.Items[intSiteNum].FindControl("PlaceHolder1");
MyControl.Controls.Add(new LiteralControl("<li>"));
MyControl.Controls.Add(btn);
MyControl.Controls.Add(new LiteralControl("</li></ul>"));
}
<ASP:Repeater id="tabs_repeater" DataSourceID="repeater_datasource"
runat="server">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<li><%#
GenerateNavBarLink((Eval("department_id").ToString()),Container.ItemIndex)
%></li>
<asplaceHolder ID="PlaceHolder1"
runat="server"></asplaceHolder>
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</ASP:Repeater>
nested inside a repeater control between <ItemTemplate> and </ItemTemplate>
tags, however I am running into problems. I've tried several different
approaches for finding the placeholder:
This:
MyControl = this.FindControl("$form$tabs_repeater$PlaceHolder1");
Produces this error:
Object reference not set to an instance of an object.
This:
MyControl =
(PlaceHolder)tabs_repeater.Items[intSiteNum].FindControl("PlaceHolder1");
Produces this error:
Index was out of range. Must be non-negative and less than the size of the
collection. Parameter name: index
Below is an abbreviated excerpt of my code. Can anyone suggest what I might
be doing wrong?
Thanks,
Brad
protected string GenerateNavBarLink(string currentdepartmentid, int SiteNum)
{
int intSiteNum = SiteNum;
string strdepartmentid = currentdepartmentid;
LinkButton btn = new LinkButton();
btn.ID = "LinkButton1";
btn.Command += new_department_button_Click;
btn.Text = "Add Department +";
Control MyControl = new Control();
// Two different ways of updating the place holder
//MyControl =
this.FindControl("form$tabs_repeater$PlaceHolder1");
//MyControl =
(PlaceHolder)tabs_repeater.Items[intSiteNum].FindControl("PlaceHolder1");
MyControl.Controls.Add(new LiteralControl("<li>"));
MyControl.Controls.Add(btn);
MyControl.Controls.Add(new LiteralControl("</li></ul>"));
}
<ASP:Repeater id="tabs_repeater" DataSourceID="repeater_datasource"
runat="server">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<li><%#
GenerateNavBarLink((Eval("department_id").ToString()),Container.ItemIndex)
%></li>
<asplaceHolder ID="PlaceHolder1"
runat="server"></asplaceHolder>
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</ASP:Repeater>