# 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]