Literal content Text=”‘ is not allowed within a ‘System.Web.UI.WebControls.DataControlFieldCollection’.

If you are receiving this error, you may be trying to bind data to a HyperLinkField in ASP.NET.  If you have a HyperLinkField, you should use the properties available to set your text in the field.

For example, the code below would cause the error.

<asp:HyperLinkField DataNavigateUrlFields=”Id_NumberDataNavigateUrlFormatString=”{0}” Text=”<%# Eval(“Id_Number”) %>” />

Essentially what I am trying to do above is have the value in the gridview column display a field from the table I am querying and also become a link where that value will be passed as a parameter to the URL  However, I cannot bind data to the HyperLinkField.

Instead, I can use another property within hyperlink field named DataTextField and set that to the column name from the table I am trying to display.  So the correct code would look like this.

<asp:HyperLinkField DataNavigateUrlFields=”Id_NumberDataNavigateUrlFormatString=”{0}DataTextField=”Id_Number” />

And that should do the trick.  If you have any questions, please post them here.  If you wish to pass multiple values over to the linked page, simply add additional fields to the property DataNavigateUrlField and separate them by commas.  Then add the references to your DataNavigateUrlFormatString property in the query string itself.


<asp:HyperLinkField DataNavigateUrlFields=”Id_Number, Name, Age, SexDataNavigateUrlFormatString=”{0}&name={1}&age={2}&sex={3}DataTextField=”Id_Number” />

If you have any questions, please post.  I’ll try to post a complete example that you can execute and customize on your server, but before I do that, I need someone to show interest in this post or someone require a more detailed example.

1 Comment

Filed under Sharing Stuff

One response to “Literal content Text=”‘ is not allowed within a ‘System.Web.UI.WebControls.DataControlFieldCollection’.

  1. Pingback: Hammad's Blog » Bind data to NavigateUrl – ASP.NET » Hammad's Blog

Comment on this

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s