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

'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: 13 Mar, 2006 05:14 PM History

Comments

Chris E
Chris E
25 Apr, 2006 02:06 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.

Said
Said
13 May, 2006 03:13 AM

Thanks Man ..that saved me lot of headache

Ramesh
Ramesh
24 May, 2006 10:13 AM

Thanks it was helpfull

Leo
Leo
16 Aug, 2006 02:04 PM

Great! I'm always trying to find such a solution. Thank you!

Kelvin
Kelvin
25 Oct, 2006 02:11 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!

Ian C
Ian C
27 Oct, 2006 02:10 AM

Thanks, just what I was after. intellisense lets us down again.

jovan blanco
jovan blanco
08 Dec, 2006 07:50 PM

this tip is so helpful!, thanks!

Mattoir
Mattoir
19 Dec, 2006 03:05 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!

RAVI
RAVI
11 Jun, 2007 07:13 AM

Thank You Very Much

I am Happy

RAVI

Doru Pirvu
Doru Pirvu
10 Jul, 2007 06:13 AM

Great!
God Bless You!

vishakha
vishakha
03 Aug, 2008 03:31 AM

Thanks a lot.

No new comments are allowed on this post.