'TextBox' cannot have children of type 'DataBoundLiteralControl'.

From what I've seen this particular error is already pretty well documented, however it is one of the things that Visual Studio is a little misleading about.

Seems this is a lesson why you can't always rely on intellisense to tell you what to type. In a datagrid, the following code will error:

Error:

<EDITITEMTEMPLATE>
<asp:TextBox id=TextBox1 runat="server">
  <%# TimeZoneInformation.ToLocalShortDateString(
(DateTime)DataBinder.Eval(Container.DataItem, "FromDate")) %>
</asp:TextBox> </EDITITEMTEMPLATE>

This will land you with a "'TextBox' cannot have children of type 'DataBoundLiteralControl'." error.

Solution.

<EDITITEMTEMPLATE>
<asp:TextBox id="TextBox1" runat="server"
value='<%# TimeZoneInformation.ToLocalShortDateString( (DateTime)DataBinder.Eval(Container.DataItem, "FromDate")) %>'> </asp:TextBox> </EditItemTemplate>

In this case the "value" tag is valid, even though intellisense doesn't think so.

.NET Code Snippets Errors and Bugs
Posted by: Brendan Kowitz
Last revised: 21 Sep 2013 12:15PM

Comments

4/25/2006 2:06:46 AM
You have no idea how grateful I am for this little gem of help, thank you!

- Chris from Cheshire, UK, currently building an estate agents website in VS.net.
5/13/2006 3:13:22 AM
Thanks Man ..that saved me lot of headache
5/24/2006 10:13:08 AM
Thanks it was helpfull
Leo
Leo
8/16/2006 2:04:00 PM
Great! I'm always trying to find such a solution. Thank you!
10/25/2006 2:11:44 PM
Without this little tip, i could have spent the last few hours trying to figure out how to get my datagrid to work. Nice one, brotha!
10/27/2006 2:10:15 AM
Thanks, just what I was after. intellisense lets us down again.
12/8/2006 7:50:37 PM
this tip is so helpful!, thanks!
12/19/2006 3:05:18 AM
I can only echo what has already been said, without this i would've been hunting round for ages and then writing lots of innefficient code. Cheers!
6/11/2007 7:13:34 AM
Thank You Very Much

I am Happy

RAVI
7/10/2007 6:13:58 AM
Great!
God Bless You!
8/3/2008 3:31:27 AM
Thanks a lot.

No new comments are allowed on this post.