Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Problem with e.item.dataitem in OnItemDataBound

Reply
Thread Tools

Problem with e.item.dataitem in OnItemDataBound

 
 
ibiza
Guest
Posts: n/a
 
      02-01-2006
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

 
Reply With Quote
 
 
 
 
Karl Seguin [MVP]
Guest
Posts: n/a
 
      02-01-2006
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> 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
>



 
Reply With Quote
 
 
 
 
ibiza
Guest
Posts: n/a
 
      02-01-2006
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!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem in OnItemDataBound yme ASP .Net 1 09-14-2007 05:45 PM
OnItemDataBound problem Mikeon ASP .Net 1 03-22-2006 10:17 PM
Problem assigning selectedItem.Value to a dropdownlist filled with OnItemDataBound Antonio D'Ottavio ASP .Net 1 09-19-2005 09:41 AM
DataGrid OnItemDataBound problem in APS.NET C# Steven ASP .Net 1 07-09-2003 05:17 PM



Advertisments