Access HeaderTemplate and FooterTemplate Controls

How to access controls in  HeaderTemplate and FooterTemplate

We are using ASP .NET, C# here in this example.

Lets take this repeater as an example. 

<asp:Repeater ID="rpt" runat="server">
    <HeaderTemplate>
       <asp:CheckBox ID="chk1" runat="server" />
    </HeaderTemplate>
    <ItemTemplate>
       HELLO
    </ItemTemplate>
    <FooterTemplate>
      
<asp:CheckBox ID="chk2" runat="server" />
    </FooterTemplate>
</asp:Repeater>

 

You can access the header and footer item controls on ItemCreated or even ItemDataBound. But not when you iterate through the repeater items like this:

foreach(RepeaterItem ri in rpt.Items)

{
    if (ri.ItemType == ListItemType.Header)
    {
        CheckBox chk1 = (CheckBox)ri.FindControl("chk1");

       chk1.Checked=true;
    }
    if (ri.ItemType == ListItemType.Footer)
    {
        CheckBox chk2 = (CheckBox)ri.FindControl("chk2");

       chk2.Checked=true;
    }
}

 

This will simply not work.

Without going through the explanation why it does not work, let see how we can get it work.

If you have a footer and header template defined in the repeater, header is item with index 0 and footer is the last item. Bearing that in mind, we can simply access the header and footer controls as follows:

CheckBox chk1 = (CheckBox)rpt.Controls[0].FindControl("chk1");
chk1.Checked = true;
CheckBox chk2 = (CheckBox)rpt.Controls[rpt.Controls.Count - 1].FindControl("chk2");
chk2.Checked = true;

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: WebCosmo
Posted on: 7/17/2008 at 11:08 AM
Categories: Programming / Coding
E-mail |  Stumble it! |  Propeller it! |  Digg it! |  del.icio.us |  Technorati
Post Information: Permalink | Comments (1) | Post RSSRSS comment feed

Marketing - Brothel Style

Few days ago a car dealer offered free gun or gas for his car buyers. Now a Nevada brothel is trying to market their business by offering free petrol.

Clients of the Shady Lady Ranch will get a $50 petrol voucher if they fork out $300 -- worth about one hour's worth of services -- at the brothel in Beatty, Nevada, 130 miles (209 km) northwest of Las Vegas.

Owner James Davis said he already has had to order another $1,000 set of petrol vouchers because the first $1,000 were spent in one week.

Currently rated 4.0 by 1 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: WebCosmo
Posted on: 7/8/2008 at 5:37 PM
Categories: Advertising / Marketing
E-mail |  Stumble it! |  Propeller it! |  Digg it! |  del.icio.us |  Technorati
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed

Marketing Goes to Ass Now

Ass-vertising is a new ad medium from a crazy advertising agency, NightAgency, which is based on a simple philosophy; "if you want to be seen, go where people are already looking". It involves putting a logo, a web address, or a brief message on the seat of a pair of bikini style panties. The panties are then worn by beautiful girls and ready to show your message to the target.

As shown part of a ass advertising campaign on the picture, bunch of shapely asses paraded outside Grand Central Station in New York to promote the New York Health and Racquet Club and a class they offer, called, appropriately, "Booty Call."

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: WebCosmo
Posted on: 7/5/2008 at 5:45 PM
Categories: Advertising / Marketing
E-mail |  Stumble it! |  Propeller it! |  Digg it! |  del.icio.us |  Technorati
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed

What are you thinking?

Currently rated 2.5 by 2 people

  • Currently 2.5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: WebCosmo
Posted on: 7/2/2008 at 5:32 PM
Categories: Funny / Bizarre / Odd / Strange
E-mail |  Stumble it! |  Propeller it! |  Digg it! |  del.icio.us |  Technorati
Post Information: Permalink | Comments (1) | Post RSSRSS comment feed