Error: Invalid code syntax for BindItem
In this article we will see how to resolve the below error
Error: Invalid code syntax for BindItem when binding a DataBound control like FormView in a web page.
I got this error when binding FormView with the datasource.
In this article we will see how to resolve the below error:
Error: Invalid code syntax for BindItem
I got this error when binding FormView with the datasource.
Here is the code which throws error:
<asp:FormView ID="FormView1" ItemType="StrongDTypeDataBoundDemo.Emp" runat="server">
<ItemTemplate>
<div>
Emp Name :
<asp:Label ID="lblEmpName" runat="server" Text='<%#BindItem.EmpName %>'></asp:Label><br />
</div>
<div>
Hire Date :
<asp:Label ID="Label2" runat="server" Text='<%#BindItem.HireDate.ToShortDateString() %>'></asp:Label>
</div>
</ItemTemplate>
</asp:FormView>
In the above code, <%#BindItem.HireDate.ToShortDateString() %> throws the error, In order to resolve this error, Instead of using BindItem, use Item as shown below:
<asp:Label ID="Label2" runat="server" Text='<%#Item.HireDate.ToShortDateString() %>'></asp:Label>