Problem with e.item.dataitem in OnItemDataBound

I

ibiza

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
 
K

Karl Seguin [MVP]

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
 
I

ibiza

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!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,805
Latest member
ClydeHeld1

Latest Threads

Top