'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"
        DataSourceID="SqlDataSource1"
        AllowPaging="True"
        PageSize="20"
        BorderStyle="None"
        BorderWidth="0px"
        Width="100%"
        CellPadding="10"
        CellSpacing="4"
        ShowHeader="False"
        >
       
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>

                   
                    <%# Container.DataItem("BlogID") %>
                   
               
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
        <PagerSettings Position="Bottom" />
        <PagerStyle HorizontalAlign="Right" />
        <RowStyle
            BackColor="#FFFEF7"
            BorderColor="Black"
            BorderWidth="1"
            BorderStyle="Dotted"
            />
        <AlternatingRowStyle BackColor="#FFFFFF" />
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:msSQLConnection %>"
        SelectCommand="SELECT * FROM Blog_Entries ORDER BY BlogID DESC">
    </asp:SqlDataSource>


http://www.krissteele.net - http://www.steeleits.com - http://www.evilscale.com - http://www.starcraftlive.net
0
Kriswd40
5/4/2008 9:20:20 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

2 Replies
1880 Views

Similar Articles

[PageSpeed] 29

If your page is written in C#, you need to use square brackets instead of paranthesises to access the collection.

<%# Container.DataItem["BlogID"] %>

Otherwise, the parser thinks that you're trying to call a method called DataItem. Paranthesises for item accessing belongs to VB.net. 


If this post was useful to you, please mark it as answer. Thank you!
0
johram
5/4/2008 9:54:50 PM

I forgot that i many of my old pages use VB instead of C#.... The acctual syntax i ended up using to get this to work was:

<%# DataBinder.Eval(Container.DataItem, "BlogID") %>

Container.DataItem doesn't seem to work quite the same way in VB as C#, as it gets errors when I try and use the square brackets too... but the idea that I was using C# instead of VB got me on the track to a solution.Thanks!


http://www.krissteele.net - http://www.steeleits.com - http://www.evilscale.com - http://www.starcraftlive.net
0
Kriswd40
5/5/2008 12:41:45 AM
Reply:

Similar Artilces:

'System.Web.UI.WebControls.DataListItem.DataItem' is a 'property' but is used like a 'method'
 HI I have a datalist with OnItemDataBoundI get the following error when I try to get the DataItem 'System.Web.UI.WebControls.DataListItem.DataItem' is a 'property' but is used like a 'method' , any idea what's wrong with the line ?  public void Item_Bound(object sender, DataListItemEventArgs e)    {        Label originalPriceLabel;        if (e.Item.ItemType == ListItemType.Item | e.Item.ItemType == ListItemType.AlternatingItem)        {    &n...

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

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

'System.Web.HttpContext.Session' is a 'property' but is used like a 'method
Hello, I'm trying to set my sessions into a class so I can set and access it easily. I get a 'System.Web.HttpContext.Session' is a 'property' but is used like a 'method' error, can you see what's wrong with my code ?  Thanks  public class SessionManager    {                public static bool isLogged        {            get        &nb...

Can any one help due to this problem Error 1 'System.Web.UI.Page.Application' is a 'property' but is used like a 'method'
Hi all ! while creating application,session variables i am getting this problem can u suggest any one. Error 1 'System.Web.UI.Page.Application' is a 'property' but is used like a 'method'  lokesh   As a general guideline for seeking help, always show the code that is not working for you.  Your description alone is not enough for us to be able to help you. Alister kplokesh: Hi all ! while creating application,session variables i am getting this problem can u suggest any one. Error 1 'System.Web.UI.Page.Application' is a 'property' but is us...

CS0118: 'System.Web.UI.WebControls.DataGridItem.DataItem' denotes a 'property' where a 'method' was expected
Hai .....,            In my datagrid, I would to display information using this ItemTemplate tag. But when i execute my page, I get the following error:CS0118: 'System.Web.UI.WebControls.DataGridItem.DataItem' denotes a 'property' where a 'method' was expected            In VB.NET, it is working perfectly but in C# it's not. I know to display data using DataBinder.Eval(Container.DataItem, "Field"), but would like Container.DataItem("Field") to work. Regards,HemantThanx and Regar...

System.Web.UI.Page.Cache is a 'property' but is used like a 'method'
if (Cache("MyData") == null){ds = myclasslibrary.lookupIDs();  <<filling datasetif (ds != null){if (ds.Tables[0].Rows.Count > 0){ddl.DataTextField = "Text";ddl.DataValueField = "ID";ddl.DataSource = ds;ddl.DataBind();Cache.Insert("MyData", ds, null,DateTime.Now.AddMinutes(5), Cache.NoSlidingExpiration);} }else{ds = ((DataSet) (Cache("MyData")));} error: System.Web.UI.Page.Cache is a 'property' but is used like a 'method'Its all about coding! Change the 2 lines that say Cache("MyData") to be Cache["MyData"] instead.If this post answered your question please remember to ...

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

System.Data.DataSet.Tables' is a 'property' but is used like a 'method'?
     private void PassID(string x)    {        //string strConnection = System.Configuration.ConfigurationManager.ConnectionStrings("FasR6ConnectionString").ConnectionString;        string strConnection = System.Configuration.ConfigurationManager.AppSettings["FasR6ConnectionString"].ToString();         SqlConnection objConnection = new SqlConnection(strConnection);        string query = "spGetEm...

is a 'property' but is used like a 'method'
Hi forum, I need some help! Ive converted a script from VB to C#. Come across the:  is a 'property' but is used like a 'method' CS0118 error. Ive searched about,  I should use [] not (). Im just not sure exactly where on this line of code, much thanks P  if ((Request("capability") != null) && (Request("userAgent") != null))   if (Request["capability"] != null && Request["userAgent"] != null)Encosia - ASP.NET, AJAX, and more.Latest article: Using complex types to make calling servic...

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

'do' won't 'do' if '/'
Greetings to All from Au, Have a NetWare Perl 5.8.4 and wanted to tweak File\Spec\NW.pm to try and standardise on '/' separators. If I run a test script (t/uni/lower.t) with an unmodified NW.pm, it calls t/uni/case.pl, that, in case.pl, (when the path separators are '\'), the $file is '..\lib\unicore\To\Lower.pl' and the following code portion works, with $simple getting a returned table: sub casetest { my ($base, $spec, $func) = @_; my $file = File::Spec->catfile(File::Spec->catdir(File::Spec->updir, "lib", &qu...

'''
Name: L Lachowsky Email: e2brutus_10atyahoodotcom Product: Firefox Summary: ''' Comments: why duddn this surprise me... I change default server from IE to Mozilla, and then i get error messages. well, shud I decide to not get on my computer with Mozilla..or shud I risk security breeches with IE....hmmm at least i can get on the internet with IE Browser Details: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5 From URL: http://hendrix.mozilla.org/ Note to readers: Hendrix gives no expectation of a response to this fee...

Web resources about - 'System.Web.UI.IDataItemContainer.DataItem' is a 'property' but is used like a 'method' - asp.net.presentation-controls

Resources last updated: 12/8/2015 1:16:07 AM