0

I want to change the text "Employer Info" to something else depending o the state of certain variables. How do I get a reference to the caption so I can change its text?

<asp:Repeater ID="rptEmployers" runat="server">
  <HeaderTemplate>
    <table class="rotoTable1">
      <caption class="rotoTableCaption1">Employer Info</caption>
  </HeaderTemplate>
Roto
  • 390
  • 2
  • 3
  • 13

2 Answers2

1

You would need to do this using the ItemDataBound event on the repeater, and updating your caption with runat=server so you can manipulate it from the code-behind.

<asp:Repeater ID="rptEmployers" OnItemDataBound="rptEmployers_ItemDataBound" runat="server">
  <HeaderTemplate>
    <table class="rotoTable1">
      <caption id="CaptionCtrl" runat="server" class="rotoTableCaption1">Employer Info</caption>
  </HeaderTemplate>

In your code behind file, you would have something like this:

protected void rptEmployers_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    switch (e.Item.ItemType)
    {
        case ListItemType.Header:

            HtmlGenericControl CaptionCtrl= (HtmlGenericControl) e.Item.FindControl("CaptionCtrl");
            CaptionCtrl.InnerHtml = "Your new text"

            break;
    }
}
Mun
  • 13,678
  • 8
  • 54
  • 82
1

You could use the ItemDataBound of the Repeater.

<asp:Repeater ID="rptEmployers" runat="server" OnItemDataBound="rptEmployers_ItemDataBound">
    <HeaderTemplate>
        <table class="rotoTable1">
            <caption class="rotoTableCaption1">
                <asp:Literal ID="EmployerCaptionLabel" runat="server" Text="Employer Info"></asp:Literal>
            </caption>
    </HeaderTemplate>

The in the code behind, set the caption to whatever you need:

protected void rptEmployers_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Header)
    {
        var employerCaption = (Literal)e.Item.FindControl("EmployerCaptionLabel");
        employerCaption.Text = "<your caption here>";
    }
}

Sarah Shelby
  • 231
  • 1
  • 6