Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 10th, 2006, 10:21 AM
Authorized User
 
Join Date: Apr 2006
Posts: 31
Thanks: 1
Thanked 0 Times in 0 Posts
Default error setting ItemTemplate asp:DataGrid

I am getting this error in Datagrid:

System.Web.UI.WebControls.DataGridColumnCollection must have items of type 'System.Web.UI.WebControls.DataGridColumn'. 'ItemTemplate' is of type 'System.Web.UI.HtmlControls.HtmlGenericControl'.

Code:
<ASP:DataGrid id="dgCart" AutoGenerateColumns="false" Width="750" CellPadding="4" HeaderStyle-VerticalAlign="bottom" DataKeyField="CartID" OnSortCommand="dgCart_Sort" OnEditCommand="dgCart_Edit" OnCancelCommand="dgCart_Cancel" OnUpdateCommand="dgCart_Update" OnDeleteCommand="dgCart_Delete" runat="server">
<HeaderStyle Font-Name="Verdana" Font-Size="8pt" Font-Bold="true" />
<ItemStyle Font-Name="Verdana" Font-Size="8pt" />
<AlternatingItemStyle Font-Name="Verdana" Font-Size="8pt" BackColor="#F1FFC7" />

<Columns>
  <asp:EditCommandColumn EditText="Edit" CancelText="Cancel" UpdateText="Update" />
    <asp:BoundColumn DataField="ItemName" HeaderText="Item" ReadOnly="true" ItemStyle-HorizontalAlign="center" HeaderStyle-HorizontalAlign="center" />                
      <asp:TemplateColumn HeaderText="Size" />
        <ItemTemplate>
          <%# Container.DataItem("ItemSize") %>
        </ItemTemplate>
        <EditItemTemplate>
          <asp:TextBox id="ItemSize" width="10" Text='<%# Container.DataItem("ItemSize") %>' runat="server" />
        </EditItemTemplate>
      </asp:TemplateColumn>
      <asp:TemplateColumn HeaderText="Color" />
        <ItemTemplate>
          <%# Container.DataItem("ItemColor") %>
        </ItemTemplate>
        <EditItemTemplate>
          <asp:TextBox id="ItemColor" width="40" Text='<%# Container.DataItem("ItemColor") %>' runat="server" />
        </EditItemTemplate>
      </asp:TemplateColumn>
      <asp:TemplateColumn HeaderText="Logo Option" />
        <ItemTemplate>
          <%# Container.DataItem("LogoOption") %>
        </ItemTemplate>
        <EditItemTemplate>
          <asp:TextBox id="LogoOption" width="25" Text='<%# Container.DataItem("LogoOption") %>' runat="server" />
        </EditItemTemplate>
      </asp:TemplateColumn>
      <asp:TemplateColumn HeaderText="Qty" />
        <ItemTemplate>
          <%# Container.DataItem("ItemQty") %>
        </ItemTemplate>
        <EditItemTemplate>
          <asp:TextBox id="ItemQty" width="5" Text='<%# Container.DataItem("ItemQty") %>' runat="server" />
        </EditItemTemplate>
      </asp:TemplateColumn>
      <asp:BoundColumn DataField="ItemPrice" ReadOnly="true" ItemStyle-HorizontalAlign="center" HeaderStyle-HorizontalAlign="center" />
</Columns>
</ASP:DataGrid>

Can someone tell me whats wrong and how to fix it?

Thanks
Jackie
 
Old April 10th, 2006, 01:09 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

You closed your TemplateColumn too early:

<asp:TemplateColumn HeaderText="Size" />

should be

<asp:TemplateColumn HeaderText="Size">

so the <ItemTemplate> is a child of the TemplateColumn.

If you post code here on this forum, can you please add a line break here and there? I am typing this reply in a screen that's about 6 foot wide.... ;)

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
 
Old April 10th, 2006, 01:47 PM
Authorized User
 
Join Date: Apr 2006
Posts: 31
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thanks! That did it!

Sorry about the line break, I didn't realize I needed to put those in. I will know better next time.



 
Old April 10th, 2006, 02:59 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

No problem. You probably just found out yourself what happens when you type really long lines here in this forum .... ;)

Glad it's working.

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004





Similar Threads
Thread Thread Starter Forum Replies Last Post
inherited web datagrid and ItemTemplate error ochanarachel General .NET 0 December 25th, 2004 04:52 PM
Setting DataNavigateURLFormatString in datagrid Renu ASP.NET 1.0 and 1.1 Basics 1 December 9th, 2004 01:32 AM
State of CheckBox in ItemTemplate of DataGrid bpgadhia Classic ASP Professional 1 August 19th, 2004 01:26 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.