Solved

Edititemplate or itemtemplate not supported message

Posted on 2011-09-29
17
374 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
 

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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now