Solved

Edititemplate or itemtemplate not supported message

Posted on 2011-09-29
17
422 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
Technology Partners: 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

Independent Software Vendors: 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!

Question has a verified solution.

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

Suggested Solutions

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

739 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