Solved

Edititemplate or itemtemplate not supported message

Posted on 2011-09-29
17
390 Views
Last Modified: 2012-05-12
I have a gridview. Inside the griview I have the followinf structure
<asp:Gridview ID="Gridview1" runat="server" Autogeneratrecolumns="false"
<columns>
   <asp:Templatefield Hedertext="Last Name:></asp:TemplateField>

 then here... Im trying to drop an EdititemTemplate or itemtemplate and ite won't take it. saying it is not supported.
0
Comment
Question by:zachvaldez
  • 9
  • 5
  • 3
17 Comments
 
LVL 12

Accepted Solution

by:
Kaushal Arora earned 250 total points
ID: 36816663
Edit Item Template is always nested in Template Field ,not out of it. Have a look at this sample gridview.
<asp:GridView ID="GridView1" Runat="server" 
                BorderColor="#3366CC" BorderStyle="None"
                CellPadding="4" BackColor="White" 
                 BorderWidth="1px" AllowPaging="True" 
                 AutoGenerateColumns="False"
                DataKeyNames="ProductID" DataSourceID="productDataSource">
                <FooterStyle ForeColor="#003399" 
                      BackColor="#99CCCC"></FooterStyle>
                <PagerStyle ForeColor="#003399" HorizontalAlign="Left" 
                       BackColor="#99CCCC"></PagerStyle>
                <HeaderStyle ForeColor="#CCCCFF" 
                  Font-Bold="True" BackColor="#003399"></HeaderStyle>
                <Columns>
                    <asp:CommandField 
                       ShowEditButton="True"></asp:CommandField>
                    <asp:BoundField ReadOnly="True" 
                       HeaderText="ProductID" InsertVisible="False" 
                       DataField="ProductID"
                        SortExpression="ProductID"></asp:BoundField>
                    <asp:TemplateField SortExpression="ProductName" 
                      HeaderText="Product"><EditItemTemplate>
                        <asp:TextBox ID="editProductName" 
                         Runat="server" 
                         Text='<%# Bind("ProductName") %>'></asp:TextBox>
                        <asp:RequiredFieldValidator 
                          ID="RequiredFieldValidator1" 
                          Runat="server" 
                       ErrorMessage="You must provide a Product Name."
                            ControlToValidate="editProductName">
                            *</asp:RequiredFieldValidator>
                    </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label Runat="server" 
                         Text='<%# Bind("ProductName") %>' 
                         ID="Label3"></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField SortExpression="UnitPrice" 
                      HeaderText="Unit Price"><EditItemTemplate>
                        <asp:TextBox ID="editUnitPrice" Runat="server" 
                          Text='<%# Bind("UnitPrice", "{0:#,##0.00}") %>' 
                          Columns="6"></asp:TextBox>
                        <asp:CompareValidator ID="CompareValidator1" 
                          Runat="server" 
ErrorMessage="You must provide a valid currency value for the Unit Price."
                            ControlToValidate="editUnitPrice" 
                   Operator="DataTypeCheck" Type="Currency">
                            *</asp:CompareValidator>
                    </EditItemTemplate>
                        <ItemStyle HorizontalAlign="Right"></ItemStyle>
                        <ItemTemplate>
                            <asp:Label Runat="server" 
               Text='<%# Bind("UnitPrice", "{0:c}") %>' 
               ID="Label1"></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField SortExpression="UnitsInStock" 
                     HeaderText="Units In Stock"><EditItemTemplate>
                        <asp:TextBox ID="editUnitsInStock" 
                 Runat="server" 
                 Text='<%# Bind("UnitsInStock") %>'
                            Columns="4"></asp:TextBox>
                        <asp:CompareValidator ID="CompareValidator2" 
                          Runat="server" 
ErrorMessage="You must provide a valid integer for Units In Stock."
                            ControlToValidate="editUnitsInStock" 
                            Operator="DataTypeCheck" Type="Integer">
                            *</asp:CompareValidator>
                    </EditItemTemplate>
                        <ItemStyle HorizontalAlign="Right"></ItemStyle>
                        <ItemTemplate>
                            <asp:Label Runat="server" 
              Text='<%# Bind("UnitsInStock") %>' 
              ID="Label2"></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
                <SelectedRowStyle ForeColor="#CCFF99" 
                   Font-Bold="True" 
                   BackColor="#009999"></SelectedRowStyle>
                <RowStyle ForeColor="#003399" BackColor="White"></RowStyle>
            </asp:GridView>

Open in new window

0
 

Author Comment

by:zachvaldez
ID: 36816742
IM just wanting to place textboxes in the field for dataentry
0
 
LVL 12

Expert Comment

by:Kaushal Arora
ID: 36816771
In the above sample i have pasted the actual GridView Design code having the EditItemTemplate.

What else you require?
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

Author Comment

by:zachvaldez
ID: 36816779
this is what i did
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
            Width="700px">
           
            <Columns>
                <asp:TemplateField HeaderText="Last Name"></asp:TemplateField>
                     
                <asp:TemplateField HeaderText="First Name"></asp:TemplateField>
                <asp:TemplateField HeaderText="Address"></asp:TemplateField>
                <asp:TemplateField HeaderText="City"></asp:TemplateField>
                <asp:TemplateField HeaderText="State"></asp:TemplateField>
                <asp:TemplateField HeaderText="Zip"></asp:TemplateField>
                <asp:TemplateField HeaderText="Phone"></asp:TemplateField>
                <asp:TemplateField HeaderText="Lunch"></asp:TemplateField>
   
        </asp:GridView>

Ijust to put textboxes in the cells.
0
 
LVL 12

Expert Comment

by:Kaushal Arora
ID: 36816915
This is what exactly a TemplateField look like with EditItemTemplate and ItemTemplate:


<asp:TemplateField SortExpression="ProductName"
                      HeaderText="Product"><EditItemTemplate>
                        <asp:TextBox ID="editProductName"
                         Runat="server"
                         Text='<%# Bind("ProductName") %>'></asp:TextBox>
                        <asp:RequiredFieldValidator
                          ID="RequiredFieldValidator1"
                          Runat="server"
                       ErrorMessage="You must provide a Product Name."
                            ControlToValidate="editProductName">
                            *</asp:RequiredFieldValidator>
                    </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label Runat="server"
                         Text='<%# Bind("ProductName") %>'
                         ID="Label3"></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>


Hope it helps you.
0
 

Author Comment

by:zachvaldez
ID: 36817011
Im not binding teh textboxes. I just want to use it to handle data entry. NO intention to display data  like from select  from table....
I just need it to insert  data to table but not select. Did I use the correct control to accomplish it?
0
 
LVL 12

Assisted Solution

by:Kaushal Arora
Kaushal Arora earned 250 total points
ID: 36817038
Then do not put the data binding value insttead use this:

<asp:TemplateField SortExpression="ProductName"
                      HeaderText="Product"><EditItemTemplate>
                        <asp:TextBox ID="editProductName"
                         Runat="server"
                         Text=""></asp:TextBox>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label Runat="server"
                         Text=""
                         ID="Label3"></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
0
 
LVL 12

Expert Comment

by:Ramkisan Jagtap
ID: 36817071
yes its correct, not needed to use edititemtemplate. Just use itemteplate by adding text box.
0
 

Author Comment

by:zachvaldez
ID: 36817229
Why can I not see the option for itemtemplae and edittemplate in the dropdown?
0
 

Author Comment

by:zachvaldez
ID: 36817354
I think i fugured out how to place the controls in the gridview. I rgiht click the gridview and select edit template. However, when I run the page it does'nt diosplay the gridview.
0
 
LVL 12

Expert Comment

by:Ramkisan Jagtap
ID: 36817399
have u bound data to gridview?
0
 

Author Comment

by:zachvaldez
ID: 36817408
NO I did not bound it because I plan to use it as front end data entry form...Should I need to?
0
 
LVL 12

Expert Comment

by:Ramkisan Jagtap
ID: 36817435
u have to bind it, of course. It will not get displayed till then.
0
 

Author Comment

by:zachvaldez
ID: 36817471
I willnot display any data though. I plan to display a blank griview
0
 
LVL 12

Expert Comment

by:Kaushal Arora
ID: 36817963
In that case you need to bound it with blank data. Coz till you dont bind some data to grid, it wont show up even with empty textboxes,
0
 

Author Comment

by:zachvaldez
ID: 36818107
 Dim pdata As New PLClass
        Dim dr As SqlDataReader
        dr = pdata.GetData
        If Page.IsPostBack = False Then
            GridView1.DataSource = dr
            GridView1.DataBind()
            GridView1.Visible = True
        End If

the Getdata class has-- Select * from table where 1 = 0.

and yet the grid wont display.  Would I need to bind the textboxes and dropdownlist tot eh fields of the class?
0
 

Author Comment

by:zachvaldez
ID: 36891663
It's still a mystery why the Blank Grid won't display.
The source look like this

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
            Width="700px">

<Columns>
                <asp:TemplateField HeaderText="Last Name">
                    <ItemTemplate>
                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("LastName") %>'></asp:TextBox>
                    </ItemTemplate>
                </asp:TemplateField>
                     
                <asp:TemplateField HeaderText="First Name">
                    <ItemTemplate>
                        <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("FirstName") %>'></asp:TextBox>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Address">
                    <ItemTemplate>
                        <asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("Address")%>'></asp:TextBox>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="City">
                    <ItemTemplate>
                        <asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("City")%>'></asp:TextBox>
                    </ItemTemplate>
                </asp:TemplateField>
</Columns>
        </asp:GridView>

Note this is wiithout edititemtemplate
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question