'DataItem' is not a member of 'System.Web.UI.Page'

I am getting this error when compiling the following code:

<%@ Import Namespace="System.IO"%>
<%@ Import Namespace="System.Data.OleDb"%>
<%@ Import Namespace="System.Data"%>
<script language="VB" runat="server">

Dim savePath As String = "C:\upload\"
Sub Upload_Click(source As Object, e As EventArgs)

  If Not (uploadedFile.PostedFile Is Nothing) Then
    Try
      Dim postedFile = uploadedFile.PostedFile
      Dim filename As String = Path.GetFileName(postedFile.FileName)
      Dim contentType As String = postedFile.ContentType
      Dim contentLength As Integer = postedFile.ContentLength

      postedFile.SaveAs(savePath & filename)
      'message.Text = postedFile.Filename & " uploaded" & _
      '  "<br>content type: " & contentType & _
      '  "<br>content length: " & contentLength.ToString()
    Catch exc As Exception
      message.Text = "Failed uploading file"
    End Try
  End If
End Sub

Sub Page_Load(source As Object, e As EventArgs)
    Dim strConn, strSQL As String
    strConn = "Provider=SQLOLEDB;Data Source=(local);Initial Catalog=Images;Trusted_Connection=Yes;"
    strSQL = "SELECT Image, DateTime FROM Image"
    Dim da As New OleDbDataAdapter(strSQL, strConn)
    Dim ds As New DataSet()
    da.Fill(ds, "Image")
    datagrid1.DataSource = ds
    datagrid1.DataMember = "Image"
    datagrid1.DataBind()
End Sub

Function FormatURL(strArgument) as String

Return ("../pictures.aspx?id=" & strArgument)

End Function


</script>

 

<html>

<head>

</head>

<body bgcolor="#C0C0C0">

<form runat="server" enctype="multipart/form-data">
<asp:DataGrid id="datagrid1" runat="server" width="100%" />
    <asp:TemplateColumn HeaderText="Image">
        <ItemTemplate>
            <asp:Image
            Width="150" Height="125"
            ImageUrl='<%# FormatURL(DataBinder.Eval(Container.DataItem, "Image")) %>'
            Runat=server />
        </ItemTemplate>
    </asp:TemplateColumn>
</asp:DataGrid>
<input id="uploadedFile" type="file" runat="server" accept="image">
<br />
<asp:Button ID="button1" Text="Submit" runat="server" OnClick="Upload_Click" />
<asp:Label id="message" runat="server" />
</form>

</body>

</html>

Any ideas?

0
msmith123006
11/18/2007 3:40:03 AM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

9 Replies
671 Views

Similar Articles

[PageSpeed] 36

Hi and welcome to forums.

Are you sure you have posted all the code from your page?  If yes, can you tell which line is getting this error?

0
codeasp
11/18/2007 8:24:50 PM

<asp:Image
            Width="150" Height="125"
            ImageUrl='<%# FormatURL(DataBinder.Eval(Container.DataItem, "Image")) %>'
            Runat=server />

This line of code is causing the error.

 

thx,

0
msmith123006
11/18/2007 10:22:04 PM

Change it to like this and see if you get any error.

<asp:Image Runat=server 
Width="150" Height="125" 
ImageUrl='<%# DataBinder.Eval(Container.DataItem, "Image", "../pictures.aspx?id={0}" ) %>' 
/>
 
0
codeasp
11/19/2007 12:16:07 AM

Yes, same error.

 Thx,

0
msmith123006
11/19/2007 12:35:23 AM

<asp:DataGrid id="datagrid1" runat="server" width="100%">
            <asp:Image Runat="server" Width="150" Height="125" ImageUrl='<%# DataBinder.Eval(Container.DataItem, "Image", "../pictures.aspx?id={0}" ) %>' />
        </asp:DataGrid>

 

I removed the / after width="100%" and before > and got rid of the error but now I am getting the error:

Type 'System.Web.UI.WebControls.DataGrid' does not have a public property named 'Image'

 thx,

0
msmith123006
11/19/2007 12:44:39 AM

Which database you are using? If you are using MS Access, the Image may be a reserved word that depends on how you are using it. (List of Microsoft Jet 4.0 reserved words:http://support.microsoft.com/kb/321266). You can try to change your select statement to:

  strSQL = "SELECT [Image] as myImage, [DateTime] as myDateTime FROM [Image]"

and  ImageUrl='<%# FormatURL(DataBinder.Eval(Container.DataItem, "myImage")) %>'

Anyway, you need to avoid to use reserved words for your system in your SQL statement (DateTime may be another one in your system).



 


Limno

0
limno
11/19/2007 12:46:18 AM

Culprit No 1. <asp:DataGrid id="datagrid1" runat="server" width="100%" />

Your datagrid declaration is finished (see the end /> tag).  That means your templatecolumn declaration is outside the datagrid and so is part of the page.  And that's reason why you are getting that error.

Culprit No 2.  TemplateColumn cannot be directly inside the DataGrid.  It has to have the Columns declaration and TEmplateColumn is the child of this.

Hope this clears up.

0
codeasp
11/19/2007 12:56:17 AM

Sub Page_Load(source As Object, e As EventArgs)
  If Not IsPostBack Then 
    Dim strConn, strSQL As String
    strConn = "Provider=SQLOLEDB;Data Source=(local);Initial Catalog=Images;Trusted_Connection=Yes;"
    strSQL = "SELECT myImage, DateTimeStamp FROM Images"
    Dim da As New OleDbDataAdapter(strSQL, strConn)
    Dim ds As New DataSet()
    da.Fill(ds, "Images")
    datalist1.DataSource = ds
    datalist1.DataMember = "Images"
    datalist1.DataBind()
  End If
End Sub

</script>

 

<html>

<head>

</head>

<body bgcolor="#C0C0C0">

<form runat="server" enctype="multipart/form-data">
<asp:DataList id="datalist1" runat="server" width="100%">
<ItemTemplate>
<asp:Image Runat="server" Width="150" Height="125" ImageUrl='<%# DataBinder.Eval(Container.DataItem, "myImage", "../pictures.aspx?id={0}" ) %>' />
</ItemTemplate>
</asp:DataList>
<input id="uploadedFile" type="file" runat="server" accept="image">
<br />
<asp:Button ID="button1" Text="Submit" runat="server" OnClick="Upload_Click" />
<asp:Label id="message" runat="server" />
</form>

</body>

</html>

New code and it works just no image shows up. I ran a statement INSERT INTO Images VALUES ('C:\Temp\Image1.jpg', '11/16/200')

And there seems to be an image in the db (I see a <BINARY> value in the myImage column).

Do I have to return the myImage in a certain way like executeBinary()?

Thx,

 

0
msmith123006
11/19/2007 1:24:18 AM

What are you storing in your database - image itself or the path to the page.  If it is the path to the image then your code above will work fine.  If you are using Image then this will not work.  Look here for a detailed tutorial on how to do this: http://www.asp.net/learn/data-access/#binary

0
codeasp
11/19/2007 1:41:59 AM
Reply:

Similar Artilces:

'DataItem' is not a member of 'System.Web.UI.Control'
I was going through the "WEb Matrix Guided Tour" and ran across the following error when I tried to do the section "ASP.NET Pages with Data (SQL Server/MSDE) DataList and Templates". I went through it three times and can not get past this point. Any suggestions would be appreciated. PS: Rookie to this, so please be kind!!! Server Error in '/' Application. -------------------------------------------------------------------------------- Compilation Error Description: An error occurred during the compilation of a resource required to service this requ...

'DataItem' is not a member of 'System.Web.UI.Control'
Hi I am getting this error on my attempt at a repeater control. Any help would be appreciated. This is the code for the HTML <asp:Repeater id="rptTests" runat="server"></asp:Repeater> <ITEMTEMPLATE> <tr style="BACKGROUND-COLOR: #ffecd8"> <td> <%# DataBinder.Eval(Container.DataItem, "test") %> </td> </tr> </ITEMTEMPLATE> This is the cod...

BC30456: 'DataItem' is not a member of 'System.Web.UI.Control'.
 I am getting compilation error (bold line): BC30456: 'DataItem' is not a member of 'System.Web.UI.Control'. I am using ASP.NET 2.0 - w/AJAX 2.0 Extension. <asp:UpdatePanel UpdateMode="Always" runat="server">             <ContentTemplate>                   <asp:LinkButton ID="rateit" runat="server" CssClass="vote" Height="56px" Width="63px&...

Error: BC30456: 'DataItem' is not a member of 'System.Web.UI.Control'.
I wanted to create a nested DataList with two dataTables.  I followed the steps.   First, set relation to the two datatables in a dataset ds1.Relations.Add("myRelation", ds1.Tables(0).Columns("intMenuItemID"), ds1.Tables(1).Columns("intParentMenu"))     Second, bind the dataset       DataList1.DataSource = ds1.Tables(0).DefaultView       DataList1.DataBind()   Third, add the following to the DataList datasource property       Container.DataItem.Row.GetChildRows("myRelation") &...

Nested repeater and BC30456: 'DataItem' is not a member of 'System.Web.UI.Control'.
I've got an application where I can make use a nested repeater... I found this Microsoft How To: http://support.microsoft.com/kb/326338/EN-US and attempted to copy that code, but I'm stuck getting the error in the subject. As far as I can tell, my code is all good but for whatever reason it's just not working the way it should. I've posted the code and code-behind pages below, if you have any thoughts on what I can do to fix this please let me know! The line that brings up the compilation error is: <asp:Repeater ID="childRepeater" Runat="server" DataSource='<...

''''''''''''''''''''
Name: haznen Email: haznenatyahoodotcom Product: Gran Paradiso Alpha 8 Summary: '''''''''''''''''''' Comments: '''''''''''''''''''''''''''''''''''' Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a1) Gecko/20061204 UGES/1.7.2.0 GranParadiso/3.0a1 From URL: http://www.mozilla.org/projects/granparadiso/ Note to readers: Hendrix gives...

'System.Web.UI.Control' does not contain a definition for 'DataItem'
Hi, I am recieving this error: 'System.Web.UI.Control' does not contain a definition for 'DataItem' What iam trying to do is when a user clicks the hyperlink column in the datagrid then the ID of that user is send to another page and I need to run the Query or something and bind the Label on the page 2 with the name of the Person. So I am using the HTML view and writing something like this : '<%# DataBinder.Eval(Container.DataItem,"Name") %> ' here is my code behind file so how can i bind the Name of the person with the label: private void Page_Lo...

'System.Web.UI.Control' does not contain a definition for 'DataItem'
Hi, I am getting this error does anyone knows how to solve this :DHighOnCodingWanna get high! Show us the code that produces this error. Other than the exactness of the error, which explains what is exactly happening, we can't see why this is happening without seeing your code.David WierMCP/ASPInsiderASPNet101.com - where to look first!Please Vote for ASPNet101 - 'Best Community Resource'!Control Grouper - easily control properties for multiple controls with one control!Calendar Express - The Best HTML Calendar Generator on the web!(Please 'Mark as Answer' when i...

'''''
Name: mario Email: ramar17atfastwebnetdotit Product: Gran Paradiso Alpha 2 Summary: ''''' Comments: K: Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a2) Gecko/20070206 GranParadiso/3.0a2 ...

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

'System.Web.UI.IDataItemContainer.DataItem' is a 'property' but is used like a 'method'
On the line "<%# Container.DataItem("BlogID") %>", I get the error listed in the title of this post. I'm not sure why, I use this same for on other pages to get data from a database and I don't get this error.         <asp:GridView ID="GridView1"         runat="server"         AutoGenerateColumns="False"         DataKeyNames="BlogID"        D...

'System.Web.UI.Control.Context' denotes a 'property' where a 'class' was expected
I get the following error when trying to compile my project. The call to Context lies in a usercontrol. It works fine when called from a page, but how do I call it from a usercontrol? private User _currentUser = new User(Context.User.Identity.Name); 'System.Web.UI.Control.Context' denotes a 'property' where a 'class' was expected Firefox - The browser you can trust Update: private User _currentUser = new User(Context.User.Identity.Name);Is declared inside the class, not in a function. Like: public class Someclass : System.Web.UI.UserControl { private User _currentUser = new...

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

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

Web resources about - 'DataItem' is not a member of 'System.Web.UI.Page' - asp.net.presentation-controls

Resources last updated: 12/29/2015 12:52:38 PM