Solved

Edititemplate or itemtemplate not supported message

Posted on 2011-09-29
17
400 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

680 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