Solved

Edititemplate or itemtemplate not supported message

Posted on 2011-09-29
17
449 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

635 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