Problem with e.item.dataitem in OnItemDataBound

Discussion in 'ASP .Net' started by ibiza, Feb 1, 2006.

  1. ibiza

    ibiza Guest

    Hi all,

    I have a simple scenario where I simply bien a repeater to a
    datasource. Here's my repeater definition :

    <asp:Repeater id="rTitles" runat="server" EnableViewState="false"
    OnItemDataBound="Bind">
    <headertemplate>
    <ul>
    </headertemplate>
    <itemtemplate>
    <li>
    <%#Eval("str1")%>
    </li>
    </itemtemplate>
    <footertemplate>
    </ul>
    </footertemplate>
    </asp:Repeater>

    So each time an item is bound, "Bind" is called, which looks like that
    (just for testing) :

    Protected Sub Bind(ByVal sender As Object, ByVal e As
    System.Web.UI.WebControls.RepeaterItemEventArgs)
    Dim drv As DataRowView = r.DataSource = e.Item.DataItem
    End Sub

    Well, "e.Item.DataItem" is always null (nothing) and that's my question
    : WHY? Because when I put the single line in Bind in comment, my
    repeater has all its data displayed, as if each row has a correct
    dataitem. Why is my dataitem always null only in the ItemDataBound
    method?

    Thank you very much,

    ibiza
     
    ibiza, Feb 1, 2006
    #1
    1. Advertising

  2. e.Item.DataItem will be null when e.Item.ItemTemplate is the HEaderTemplate
    or FooterTemplate. You should check to see if you're in the footer/header
    first, and if not try to access e.Item.DataItem.

    Also, you clearly have option strict off, you should turn it on, you might
    see some bugs in your actual line...not sure..I never know how operator
    precedence works in VB :)

    Karl
    --
    http://www.openmymind.net/



    "ibiza" <> wrote in message
    news:...
    > Hi all,
    >
    > I have a simple scenario where I simply bien a repeater to a
    > datasource. Here's my repeater definition :
    >
    > <asp:Repeater id="rTitles" runat="server" EnableViewState="false"
    > OnItemDataBound="Bind">
    > <headertemplate>
    > <ul>
    > </headertemplate>
    > <itemtemplate>
    > <li>
    > <%#Eval("str1")%>
    > </li>
    > </itemtemplate>
    > <footertemplate>
    > </ul>
    > </footertemplate>
    > </asp:Repeater>
    >
    > So each time an item is bound, "Bind" is called, which looks like that
    > (just for testing) :
    >
    > Protected Sub Bind(ByVal sender As Object, ByVal e As
    > System.Web.UI.WebControls.RepeaterItemEventArgs)
    > Dim drv As DataRowView = r.DataSource = e.Item.DataItem
    > End Sub
    >
    > Well, "e.Item.DataItem" is always null (nothing) and that's my question
    > : WHY? Because when I put the single line in Bind in comment, my
    > repeater has all its data displayed, as if each row has a correct
    > dataitem. Why is my dataitem always null only in the ItemDataBound
    > method?
    >
    > Thank you very much,
    >
    > ibiza
    >
     
    Karl Seguin [MVP], Feb 1, 2006
    #2
    1. Advertising

  3. ibiza

    ibiza Guest

    errr, thank you

    I added the correct "if" and it works. As the two "=" on the same line,
    it's obviously not good to have that "= r.DataSource", *#*%&
    copy-paste...

    Thanks!
     
    ibiza, Feb 1, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kel Good
    Replies:
    2
    Views:
    13,149
    Kel Good
    Apr 25, 2004
  2. MattB
    Replies:
    4
    Views:
    21,305
  3. Peter Rilling
    Replies:
    1
    Views:
    1,017
    =?Utf-8?B?RWx0b24gVw==?=
    May 19, 2005
  4. Skowronek
    Replies:
    4
    Views:
    4,536
    ProgTalk
    Dec 4, 2007
  5. kidpurple

    OnItemDatabound requires Item or AlternatingItem and Item?

    kidpurple, Nov 2, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    273
    kidpurple
    Nov 2, 2004
Loading...

Share This Page