The base class includes the field 'MyList', but its type (System.Web.UI.WebControls.DataList) is not compatible with the type of control (System.Web.UI.WebControls.DataGrid).

Hi guys,

I am very new to asp.net and have been playing with the commerce starter kit at - http://asp.net/CommerceStarterKit/ one of the first pages that lists the catalogue items "ProductsList.aspx" uses a datalist, I need to use a datagrid as I need to use pagination as my catalogue is so huge, I have changed the necessary attributes in the ProductsList.aspx page to datagrid and also in the codebehind file ProductsList.aspx.vb, when I run the page I get the Error message below. 

Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: The base class includes the field 'MyList', but its type (System.Web.UI.WebControls.DataList) is not compatible with the type of control (System.Web.UI.WebControls.DataGrid).

Source Error:

Line 30:                                     <tr>
Line 31:                                         <td>
Line 32: 									<asp:DataGrid id="MyList" runat="server">
Line 33:                                     <Columns>
Line 34:                                          <asp:TemplateColumn>


HERE IS THE PRODUCTSLIST.ASCX PAGE

<%@ Page Language="vb" EnableViewState="false" CodeBehind="ProductsList.aspx.vb" AutoEventWireup="false" Inherits="ASPNET.StarterKit.Commerce.ProductsList"%>
<%@ Register TagPrefix="ASPNETCommerce" TagName="Search1" Src="Search1.ascx" %>
<%@ Register TagPrefix="ASPNETCommerce" TagName="Menu" Src="_Menu.ascx" %>
<%@ Register TagPrefix="ASPNETCommerce" TagName="Header1" Src="Header1.ascx" %>
<%@ Register TagPrefix="ASPNETCommerce" TagName="Footer1" Src="Footer1.ascx" %>
<%@ OutputCache Duration="6000" VaryByParam="CategoryID" %>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<link rel="stylesheet" type="text/css" href="ASPNETCommerce.css">
</head>

<body>

<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td height="119" colspan="3"><ASPNETCommerce:Header1 ID="Header1" runat="server" /></td>
  </tr>
  <tr>
    <td height="30" colspan="3"><ASPNETCommerce:Search1 ID="Search1" runat="server" /></td>
  </tr>
  <tr>
    <td valign="top" width="151" height="100%" rowspan="2" nowrap background="Images/left1.jpg"><ASPNETCommerce:Menu id="Menu1" runat="server" />
 </td>
 <td><form id="Form1" runat="server">
        
                        <table cellSpacing="0" cellPadding="0" width="100%" border="0" valign="top">
                                    <tr>
                                        <td>
         <asp:DataGrid id="MyList" runat="server">
                                    <Columns>
                                         <asp:TemplateColumn>
                                    <ItemTemplate>       
                                          <table border="0" width="300">
                                            <tr>
                                                <td width="25">
                                                    &nbsp
                                                </td>
                                             
               <td width="100" valign="middle" align="right">
                                                    <a href='ProductDetails.aspx?productID=<%# DataBinder.Eval(Container.DataItem, "ProductID") %>'>
                                                        <img src='ProductImages/thumbs/<%# DataBinder.Eval(Container.DataItem, "ProductImage") %>' width="100" height="75" border="0">
                                                    </a>
                                                </td>
            <td width="200" valign="middle">
                                                    <a href='ProductDetails.aspx?productID=<%# DataBinder.Eval(Container.DataItem, "ProductID") %>'>
                                                        <span class="ProductListHead">
                                                            <%# DataBinder.Eval(Container.DataItem, "ModelName") %>
                                                        </span>
                                                        <br>
                                                    </a><span class="ProductListItem"><b>Special Price: </b>
                                                        <%# DataBinder.Eval(Container.DataItem, "UnitCost", "{0:c}") %>
                                                    </span>
                                                    <br>
                                                    <a href='AddToCart.aspx?productID=<%# DataBinder.Eval(Container.DataItem, "ProductID") %>'>
                                                        <span class="ProductListItem"><font color="#9D0000"><b>Add To Cart<b></font></span>
                                                    </a>
                                                </td>
                                            </tr>
                                        </table>
                                    </ItemTemplate>
         </asp:TemplateColumn>
         </columns>
                                </asp:DataGrid>
       </table> 
      </form>
</td>
  </tr>
 
  <tr>
    <td width="624" background="Images/basemenu1.jpg">
 
  <table width="100%" border="0" cellpadding="2" cellspacing="2">
      <tr>
        <td width="308">&nbsp;</td>
        <td width="280">&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
  </table>
 
  </td>
 
    <td width="565" background="Images/basemenu1.jpg"><table width="100%" border="0" cellpadding="2" cellspacing="2">
      <tr>
        <td width="308">&nbsp;</td>
        <td width="280">&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
    </table>
  
  </td>
  </tr>
  <tr>
    <td colspan="3"><ASPNETCommerce:Footer1 ID="Footer1" runat="server" /></td>
  </tr>
</table>
</body>
</html>

AND HERE IS THE CODE BEHIND FILE PRODUCTSLIST.ASCX.VB

Public Class ProductsList
    Imports System.Web
    Protected WithEvents MyList As System.Web.UI.WebControls.DataGrid

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    '*******************************************************
    '
    ' The Page_Load event on this page is used to obtain
    ' from a database a collection of all products within a
    ' specified product category.  The collection is then
    ' databound to a templated asp:datalist control.
    '
    ' The product category to obtain is specified using
    ' a querystring argument to the page.
    '
    ' Note that this page is output cached at 1 hour
    ' intervals.  This eliminates the need to hit the database
    ' on each request to the page.
    '
    '*******************************************************

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        ' Obtain categoryId from QueryString
        Dim categoryId As Integer = CInt(Request.Params("CategoryID"))

        ' Obtain products and databind to an asp:datalist control
        Dim productCatalogue As ASPNET.StarterKit.Commerce.ProductsDB = New ASPNET.StarterKit.Commerce.ProductsDB()


        MyList.DataSource = productCatalogue.GetProducts(categoryId)
        MyList.DataBind()

    End Sub

End Class



If anyone can help me I would appreciate it.

Cheers

0
Stoater
9/16/2005 8:48:39 PM
asp.net.commerce-starter-kit 1165 articles. 0 followers. Follow

3 Replies
1541 Views

Similar Articles

[PageSpeed] 18

Hello

Have you found a resolution to this problem ?

Cos I have a similar problem.

google keyword : The base class includes the field  but its type  is not compatible with the type of control

 

 

0
pronyce
12/25/2005 1:32:40 PM

Try and remove the id="..." from the controls that you are having problems with.


Plese, do not forget to click "Mark as Answer" on the post that helped you. Thanx!

My blog: Scenes From A Developer Memory
0
dt008
9/6/2007 9:14:40 PM

I've been lurking all around for an answer to this problem. I have yet to find the cause but yout solution worked.

thank you very much!

(also this is my very first post)

0
raindogmx
10/8/2007 7:20:50 AM
Reply:

Similar Artilces:

Unable to cast object of type 'System.Web.UI.WebControls.FormView' to type 'System.Web.UI.WebControls.DropDownList'.
Hi,  I have a formview with a dropdownlist created dynamically. i want to determine whether the dropdownlist was clicked. the code is written in the FormView1_DataBound method. I get the following error in the line below that is in italics and underlined: Unable to cast object of type 'System.Web.UI.WebControls.FormView' to type 'System.Web.UI.WebControls.DropDownList'.   Here is my code: ddl_iFullname = New DropDownList ddl_iFullname.ID = "ddl_iFullname" ddl_iFullname.DataSource = ObjectDataSource3 ddl_iFullname.DataTextField = "fullname" ddl_iFullname.DataValueField = "...

Unable to cast object of type 'System.Web.UI.WebControls.Label' to type 'System.Web.UI.WebControls.TextBox'
I am attempting to "Update" a field in a Datagrid, but no matter what I do (Using either Label or Text Boxes)  I keep getting the same error: Unable to cast object of type 'System.Web.UI.WebControls.Label' to type 'System.Web.UI.WebControls.TextBox' The Error is highlighted below in the Sub... <==THE FIELD THAT CALLS THE ERROR  Any help would be greatly appreciated !!! Thanks !!   The code is as follows... <table border=0 height=210 bordercolor=olive ><tr valign=top><td> <asp:datagrid id="FacilityDataGrid"...

Error: Cannot convert type 'System.Web.UI.Control' to 'System.Web.UI.WebControls.ButtonField'
Hello, I am getting the following error during compiliation. Any suggestions to fix it. Thanks. Cannot convert type 'System.Web.UI.Control' to 'System.Web.UI.WebControls.ButtonField' protected void gvEvents_RowCommand(Object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Select") { int index = Convert.ToInt32(e.CommandArgument); GridViewRow selectedRow = gvEvents.Rows[index]; string sID; ButtonField btn; if (selectedRow.RowType == DataControlRowType.DataRow) { sID = ((ButtonField)selectedRow.FindControl("ID")).DataTextFi...

Error Serializing Value 'System.Web.UI.WebCOntrols.TreeNode' of type 'System.Web.UI.WebCOntrols.TreeNode'
Hi, I am  getting the error stated in the subject when i am storing a TreeNode in a ViewState and then using it as follows if (ViewState["ProductCounty"]!=null) { TreeNode _productCountyNode = DataTree.FindNode(((TreeNode)ViewState["ProductCounty"]).ValuePath); _productCountyNode.Expand(); } what could be causing this error? Hi, I believe TreeNode isn't serializable in a way its required for objects which can be put to ViewState - as reference - (TreeNode implements IStateManager and is meant to work together with TreeView itself saving it...

Unable to cast object of type 'System.Web.UI.LiteralControl' to type 'System.Web.UI.WebControls.TextBox'.
Hi, any idea why I'm getting the following error?Line 45: protected void CartGrid_RowUpdating(object sender, System.Web.UI.WebControls.GridViewUpdateEventArgs e) Line 46: { Line 47: TextBox QuantityTextBox = (TextBox)CartGrid.Rows[e.RowIndex].Cells[2].Controls[0]; Line 48: int Quantity = Convert.ToInt32(QuantityTextBox.Text); Line 49: Are you sure that the control at CartGrid.Rows[e.RowIndex].Cells[2].Controls[0] isn't a LiteralControl?  How are you creating code this in your code?Brent JenkinsASP.NET, C#, Web Developerwww.valewebdesign.co.uk  ...

Unable to cast object of type 'System.Web.UI.LiteralControl' to type 'System.Web.UI.WebControls.TextBox'
Hello, Goal: enter a number in two fields HoursPerUnit and PeoplePerUnit and the value for the third field, TotalHoursPerUnit will populate after the the number in the two fields have been caculated.  Using the code below I receive the error message above.  Please tell me what am I doing wrong? Do I need to cast the text as a literal?  Please help? Thank you in advance, <%@ Page Language="VB" MasterPageFile="Default.master" AutoEventWireup="false" CodeFile="frmHR.aspx.vb" Inherits="frmHR"...

ASPNET2 HELP! CS0266: Cannot implicitly convert type 'System.Web.UI.Control' to 'System.Web.UI.WebControls.FileUpload'.
Server Error in '/start-movieposters' Application. Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS0266: Cannot implicitly convert type 'System.Web.UI.Control' to 'System.Web.UI.WebControls.FileUpload'. An explicit conversion exists (are you missing a cast?) Source Error: ...

Error 1 The type 'System.Web.UI.WebControls.LinqDataSource' exists in both 'c:\WINDOWS\assembly\GAC_MSIL\System.Web.Extensions\3.5.0.0__31bf3856ad364e35\System.Web.Extensions.dll' and 'c:\WINDOWS\asse
Once I build project. I encounter this error. Does someone experience this error?Error    1    The type 'System.Web.UI.WebControls.LinqDataSource' exists in both 'c:\WINDOWS\assembly\GAC_MSIL\System.Web.Extensions\3.5.0.0__31bf3856ad364e35\System.Web.Extensions.dll' and 'c:\WINDOWS\assembly\GAC_MSIL\System.Web.Extensions\3.6.0.0__31bf3856ad364e35\System.Web.Extensions.dll'    D:\Source Code\Linq_Lesson5\Default.aspx    1    1    D:\Source Code\Linq_Lesson5\  It appears tha...

Unable to cast object of type 'System.String' to type 'System.Web.UI.WebControls.Parameter'.
I'm getting this error on a vb.net page the needs to execute two separate stored procedures.  The first one, is the main insert, and returns the identity value for the ClientID.  The second stored procedure inserts data, but needs to insert the ClientID returned in the first stored procedure.  What am I doing wrong with including the identity value "ClientID" in the second stored procedure?  Unable to cast object of type 'System.String' to type 'System.Web.UI.WebControls.Parameter'. Description: An unhandled exception occurred during t...

Unable to cast object of type 'System.EventArgs' to type 'System.Web.UI.WebControls.GridViewRowEventArgs'
hi this is really really bugging me please help. I have a web appliction that uses a Master Page. On one of the content pages I am presenting a gridview control bound to a spreadsheet. The gridview is contained within an ajax update panel. I want to add attributes to the rows of the gridview control once databound (mouseover effect). However I am getting the following error:- Unable to cast object of type 'System.EventArgs' to type 'System.Web.UI.WebControls.GridViewRowEventArgs' Can anyone help please. Here is the aspx code:-  <%@ Page Language="v...

Unable to cast object of type 'System.Int32' to type 'System.Web.UI.WebControls.DataKey'
hi , i have a datalist with an itemtemplate section that contains an image and a delete button to delete the corresponding image . <asp:DataList ID="DataList1" CellSpacing="25" runat="server" DataSourceID="sqldatasource3" DataKeyField="ID" repeatColumns="4" repeatdirection="Horizontal" BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="0px" CellPadding="3" > <ItemTemplate> <table border="0" cellpadding="0" cellspacing="0" > <tr> <a href='<%# DataBinder.Eval(Container.DataItem, "image", "ImageViewer.aspx?id={0}") %>' > <img a...

Error showing up: Unable to cast object of type 'System.Web.UI.WebControls.TextBox' to type 'System.IConvertible'.
Hi, I am trying to pass date values from two textboxes in a stored procedure from ASP.net page. However, it seems it is not passing the date properly. I am getting the following error at the following line: cmd_r.Parameters("@initial_est_date").Value = Convert.ToDateTime(Textbox1)  and the error is as stated in the title. I would appreciate any help to resolve this. Thanks  CODE:<%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.SqlClient" %><%@ Import Namespace="System.Data.Common" %> <%@ I...

Value of type 'System.Web.UI.Control' cannot be converted to 'System.Web.SiteMap'.
 Hello,         I receive this error "System.Web.UI.Control' cannot be converted to 'System.Web.SiteMap" when I try to find the Sitemap control.  ...            <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />            <asp:ListView ID="ListView1" runat="server">            <LayoutTemplate>    ...

Web resources about - The base class includes the field 'MyList', but its type (System.Web.UI.WebControls.DataList) is not compatible with the type of control (System.Web.UI.WebControls.DataGrid). - asp.net.commerce-starter-kit

Resources last updated: 12/27/2015 8:59:39 PM