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

  • SEARCH
  • Home
  • 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

please consider this code: <asp:TemplateField> <ItemTemplate> <asp:LinkButton runat=server ID=linkmodel Text='<%#Eval(MenuItem) %>' CommandName='<%#Eval(CommandName) %>' OnCommand=linkmodel_Click
This is my code: <asp:TemplateField HeaderText=Email> <ItemTemplate> <asp:TextBox ID=txtEmail runat=server Text='<%# Eval(Email) %>' Width=88px
This is what my aspx page looks like: <asp:TemplateField HeaderText=Detail HeaderStyle-ForeColor=DimGray > <ItemTemplate> <asp:Label
I have a simple gridview ItemTemplate that looks like this: <asp:TemplateField HeaderText=User> <ItemTemplate> <a
Suppose I have one template field TemplateField FooterField = new TemplateField(); FooterField.ItemTemplate = //my
I have a GridView that I need to dynamically add TemplateField elements to. My
I currently have an asp:GridView that displays a few BoundFields and then one asp:TemplateField
Inside of a GridView's TemplateField i have a HTML-TextArea: <asp:TemplateField HeaderText=Message> <ItemTemplate> <textarea id=txtArStatusMsg
<asp:TemplateField HeaderText=Quantity ItemStyle-HorizontalAlign=Left HeaderStyle-HorizontalAlign=Left> <ItemTemplate> <%#GetQuantityRemaining((int) Eval(Id)) %> </ItemTemplate> <HeaderStyle HorizontalAlign=Left></HeaderStyle> <ItemStyle HorizontalAlign=Left></ItemStyle> </asp:TemplateField>
//code in aspx. </asp:TemplateField> : : : <ItemTemplate> <asp:DropDownList ID=didDdl runat=server DataSourceID=departmentsDataSource DataTextField=Department DataValueField=DepartmentID

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.