Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 501395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:11:07+00:00 2026-05-13T06:11:07+00:00

TemplateField tf1 = new TemplateField(); tf1.ItemTemplate = ??? How to initialize this property? If

  • 0
TemplateField tf1 = new TemplateField(); 
tf1.ItemTemplate = ???

How to initialize this property?

If I need to this programmatically then what to do?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T06:11:07+00:00Added an answer on May 13, 2026 at 6:11 am

    You would usually do this sort of thing in the markup:

    <TemplateField ...>
        <ItemTemplate>
           <asp:TextBox .../>
        </ItemTemplate>
    </TemplateField>
    

    or do the same thing using the designer.


    Example follows. The commented-out markup produces the same thing as the codebehind does:

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:AdventureWorksConnectionString %>" 
            SelectCommand="SELECT Person.Contact.FirstName, Person.Contact.LastName 
            FROM Person.Contact 
            INNER JOIN HumanResources.Employee ON Person.Contact.ContactID = HumanResources.Employee.ContactID 
            WHERE (Person.Contact.LastName LIKE N'A%') 
            ORDER BY Person.Contact.LastName, Person.Contact.FirstName">
        </asp:SqlDataSource>
        <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
    <%--        <ItemTemplate>
                <asp:Label runat="server" ID="lblLast">Name:&nbsp;</asp:Label>
                <asp:Label runat="server" ID="lblName" Text='<%# DataBinder.Eval(Container.DataItem, "LastName")+", "+DataBinder.Eval(Container.DataItem, "FirstName") %>' />
            </ItemTemplate>--%>
            <SeparatorTemplate>
                <hr />
            </SeparatorTemplate>
        </asp:Repeater>
        </form>
    </body>
    </html>
    

    Codebehind:

    using System;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    public partial class _Default : Page
    {
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            Repeater1.ItemTemplate = new TheItemTemplate();
        }
    
        protected void Page_Load(object sender, EventArgs e)
        {
            DataBind();
        }
    }
    
    public class TheItemTemplate : ITemplate
    {
        #region Implementation of ITemplate
    
        public void InstantiateIn(Control container)
        {
            var lblLast = new Label {ID = "lblLast", Text = "Name: "};
            container.Controls.Add(lblLast);
    
            var lblName = new Label {ID = "lblName"};
            lblName.DataBinding += delegate(object sender, EventArgs e)
                                   {
                                       var theLabel = (Label) sender;
                                       var dataItem = DataBinder.GetDataItem(theLabel.BindingContainer);
                                       theLabel.Text = DataBinder.Eval(dataItem, "LastName") + ", " +
                                                       DataBinder.Eval(dataItem, "FirstName");
                                   };
            container.Controls.Add(lblName);
        }
    
        #endregion
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using a label control in ItemTemplate tag in TemplateField tag in Gridview
I have this code until now: <asp:TemplateField ShowHeader=False ItemStyle-Width=150px HeaderStyle-BackColor=#003ca1 HeaderStyle-ForeColor=white> <ItemTemplate> <asp:LinkButton ID=linkDelete
C#, .net Original Code: <asp:TemplateField ItemStyle-Width=20px ItemStyle-HorizontalAlign=Center> <itemtemplate> <asp:Label ID=lblDependency Runat=server></asp:Label> </itemtemplate> </asp:TemplateField> I'd
I have a TemplateField in a DetailsView and its input should be one of
Here's my code: <asp:TemplateField HeaderText=* License Setup Date> <EditItemTemplate> <asp:RequiredFieldValidator ID=LicenseSetupDateRequired ErrorMessage=License Setup Date
I have a gridview that I have added a checkbox column using a templatefield
I have a Gridview with ImageButtons added to a column via a templatefield. I've
Here's my code in a gridview that is bound at runtime: ... <asp:templatefield> <edititemtemplate>
I have a TemplateField in a GridView in an UpdatePanel with a button called
I'm trying to use CheckBoxes within a GridView's TemplateField to select multiple entries from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.