# Monday, November 13, 2006

This evening I was going to do something very simple: bind a couple of columns in a DataRow to a Repeater control on one of my ASP.NET pages. I coded everything straight through and compiled without thinking much about it. However, to my surprise I got a runtime error when I opened the page with the control on it. Much more to my surprise the error was stating that a column the DataRow I had bound to did not exist. Problem is, the column did exist and was spelled exactly like the column being reported as an error.

DataBinder.Eval: 'System.Data.DataRow' does not contain a property with the name dtCommentDate.

I looked at the documentation for DataBinder and it looked just like mine. My code looked like this:

<asp:repeater id="_rptComments" Runat="server">
   <ItemTemplate>
      <asp:Label ID="_lblDate" Runat="server">
         <%# DataBinder.Eval(CType(Container.DataItem, System.Data.DataRow), "dtCommentDate")%>
      </asp:Label>
   </ItemTemplate>
</asp:repeater>

which matched what the documentation said exactly. So, I beat my head against a wall for an hour or so trying to figure out exactly what was wrong.

After spending much time tweaking the syntax, getting some things to work, finding most failed, I noticed something about the above error that I had not caught my eye until this point. That is the word "property." I had assumed that the DataBinder.Eval() call was attempting to bind against a column or Item or something that used the "dtCommentDate" as a key. However, this error is telling me that "dtCommentDate" is being bound directly to the DataRow object as a property accessor. With this in mind I tried one last syntactical change:

<asp:repeater id="_rptComments" Runat="server">
   <ItemTemplate>
      <asp:Label ID="_lblDate" Runat="server">
         <%# DataBinder.Eval(CType(Container.DataItem, System.Data.DataRow), "(dtCommentDate)")%>
      </asp:Label>
   </ItemTemplate>
</asp:repeater>

Notice the parenthesis that surround the dtCommentDate. Since the contents of the second parameter are directly bound to the DataItem object, in this case that means that the Item accessor syntax of the parenthesis is necessary.

In my looking around the Internet for a solution to my problem I did not find an example like this so I wanted to post it here in hopes that it will help someone else.

posted on Monday, November 13, 2006 10:31:15 PM (Central Standard Time, UTC-06:00)  #    Comments [3]
Monday, December 04, 2006 6:23:42 AM (Central Standard Time, UTC-06:00)
Thanks a lot.
Joel Alexandre
Friday, May 25, 2007 5:10:06 AM (Central Daylight Time, UTC-05:00)
Thanks, it helps for understanding but I still have the problem :D

My field have a name containing a parenthesis, coming from an excel file witch is the original datasource ( converted into a serialised XML Dataset )

Adding the parenthesis changes the error message but there is still and error ...

Example :
Original column name = "DRINKING CAPACITY (m3/day)"

Error messsage without parenthesis :
"DRINKING CAPACITY "
Message with parenthesis :
"DRINKING CAPACITY (m3/day"

I'm going crazy ...
Franck
Wednesday, June 06, 2007 3:04:07 PM (Central Daylight Time, UTC-05:00)
Thanks a lot. i would have never thought about this. It worked for me. once again thanks a lot. Great job..keep posting such good solutions.
sheetal
Comments are closed.