'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.

Print | posted on Monday, March 13, 2006 5:14 AM

&uot&uot

Comments on this post

# Thank you!

Requesting Gravatar...
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.
Left by Chris E on Apr 24, 2006 2:06 PM

# Thanks

Requesting Gravatar...
Thanks Man ..that saved me lot of headache
Left by Said on May 12, 2006 3:13 PM

# Thanks it was helpful

Requesting Gravatar...
Thanks it was helpfull
Left by Ramesh on May 23, 2006 10:13 PM

# Thanks!

Requesting Gravatar...
Great! I'm always trying to find such a solution. Thank you!
Left by Leo on Aug 16, 2006 2:04 AM

# Thanks a million!

Requesting Gravatar...
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!
Left by Kelvin on Oct 25, 2006 2:11 AM

# Thanks

Requesting Gravatar...
Thanks, just what I was after. intellisense lets us down again.
Left by Ian C on Oct 26, 2006 2:10 PM

# RE: 'TextBox' cannot have children of type 'DataBoundLiteralControl'.

Requesting Gravatar...
this tip is so helpful!, thanks!
Left by jovan blanco on Dec 08, 2006 6:50 AM

# RE: 'TextBox' cannot have children of type 'DataBoundLiteralControl'.

Requesting Gravatar...
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!
Left by Mattoir on Dec 18, 2006 2:05 PM

# re: 'TextBox' cannot have children of type 'DataBoundLiteralControl'.

Requesting Gravatar...
Thank You Very Much

I am Happy

RAVI
Left by RAVI on Jun 10, 2007 7:13 PM

# re: 'TextBox' cannot have children of type 'DataBoundLiteralControl'.

Requesting Gravatar...
Great!
God Bless You!
Left by Doru Pirvu on Jul 09, 2007 6:13 PM

# re: 'TextBox' cannot have children of type 'DataBoundLiteralControl'.

Requesting Gravatar...
This is Great! But having the same problem with Select listbox which this solution does not work.
Left by Barry on Apr 25, 2008 6:15 AM

# re: 'TextBox' cannot have children of type 'DataBoundLiteralControl'.

Requesting Gravatar...
Thanks a lot.
Left by vishakha on Aug 02, 2008 3:31 PM

Your comment:

 (will show your gravatar)
 
Please add 3 and 1 and type the answer here: