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

If anyone can help me I would appreciate it.

Cheers

0
Stoater
9/16/2005 4:33:35 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

10 Replies
2775 Views

Similar Articles

[PageSpeed] 23

You probably have changed the control in the HTML by writing it. That will not change the declaration in the webforms hidden code . Check the section that says: "Web Form Designer Generated Code" and change the declaration there from datalist to datagrid for that control.
Sonu Kapoor [MVP]
Feel free to ask me any .NET question | Ajax Data Controls Forum
0
SonuKapoor
9/16/2005 4:55:46 PM

Thanks for your reply sonu that was bloody quick, I dont see any refrence to the datalist here though, except in the private sub page load area, any other suggestions?

Cheers

The code behind file is

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

0
Stoater
9/16/2005 5:19:43 PM

According to the error the base class already contains an object MyList with another declaration. Can you search your project for the "MyList" and see what it outputs?


Sonu Kapoor [MVP]
Feel free to ask me any .NET question | Ajax Data Controls Forum
0
SonuKapoor
9/16/2005 5:55:53 PM
well I have searched for MyList and gone thru all the entries and have searched DataGrid and gone thru all those too no luck, Ill just have to keep playing, cheers
0
Stoater
9/16/2005 8:50:08 PM
Can you rename it to something else and try again please?
Sonu Kapoor [MVP]
Feel free to ask me any .NET question | Ajax Data Controls Forum
0
SonuKapoor
9/16/2005 9:48:42 PM

Hi SonuKapoor,

 

Thanks for sticking with me on this one,

what did you want me to rename, I renamed the DatGrid to MyJK in the code behind file and the aspx file now I get a different error:

 

Server Error in '/Commerce' Application.

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
   ASPNET.StarterKit.Commerce.ProductsList.Page_Load(Object sender, EventArgs e)
   System.Web.UI.Control.OnLoad(EventArgs e) +67
   System.Web.UI.Control.LoadRecursive() +35
   System.Web.UI.Page.ProcessRequestMain() +750


Cheers

Jonathan
0
Stoater
9/19/2005 4:34:01 PM
Well you will need to change the datagrid name also in the codebehind. Did you do that?

The reason why I asked to change the datagrid name is that it seems that somehow there is already a variable with the name MyList.
Sonu Kapoor [MVP]
Feel free to ask me any .NET question | Ajax Data Controls Forum
0
SonuKapoor
9/19/2005 5:26:46 PM

Yes I changed both of them and now the Object Reference not set to an instance of the object error appears.

0
Stoater
9/19/2005 5:56:26 PM

I just noticed the shopping cart uses a datagrid called MyList as well and that page works fine.

0
Stoater
9/19/2005 5:58:04 PM

Hello SonuKapoor,

 

I guess I need to use a data set instead of a datareader, any ideas how to implement this is the 2 pages of code

0
Stoater
9/19/2005 7:45:13 PM
Reply:

Similar Artilces:

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...

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"...

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: ...

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  ...

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'
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"...

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...

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>    ...

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.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...

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...

Extender controls of type 'AjaxControlToolkit.DragPanelExtender' cannot extend controls of type 'System.Web.UI.HtmlControls.HtmlGenericControl'.
Hi, I'm getting this error when trying to port an old Atlas Web App to use the latest bits - any help would be nice as to what controls I CAN extend - so if I can't use a DIV what then?: Server Error in '/GRintranets' Application. Extender control 'DragPanelExtender1' cannot extend 'divPaginaHTML'. Extender controls of type 'AjaxControlToolkit.DragPanelExtender' cannot extend controls of type 'System.Web.UI.HtmlControls.HtmlGenericControl'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more informati...

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.presentation-controls

Resources last updated: 1/6/2016 10:00:59 AM