views:

265

answers:

2

Hi there,

The scenario I'm dealing with is I have a set of entries in a database that have an image associated with them. This image needs to be 'accepted' or 'rejected' via a web interface.

I'm using ASP.NET WebForms.

I'm attempting to databind my recordset of entires to a CheckBoxList control. I would like to combine data from my dataset with information from the web.config file and plain text to display an image:

<asp:CheckBoxList ID="CheckBoxList1" runat="server" 
 DataSourceID="DataSource1" 
 DataTextField="ImageIdentifier" 
 DataValueField="EntryId"  
 DataTextFormatString="<img src='<%$ AppSettings:GetImageUrl %>{0}' />" />

This approach correctly outputs the plain text and the DataTextField value, however it does not interpret the code inside the <% %> block and prints the whole thing literally in the generated HTML, in spite of it being correctly highlighted in the editor.

Is this possible to achieve declaratively? If not, is there a better way than iterating through the entries in the list in code on the OnDataBound event?

Thanks in advance,

Jamie

A: 

What does your web.config look like? You'll won't be able to use that binding syntax here - you'll have to hook into the databound event of the checkbox and iterate each checkbox, updating them as necessary from the values in your web.config.

EDIT

If you don't want to iterate each checkbox after the checkboxlist has been databound, you'll have to update your dataset first, before you bind to it.

ScottE
+1  A: 

I believe you're using the wrong <% tag. In order to evaluate in a binding expression like that it should be <%#

Joel Etherton
I'm not sure this will work but, to even have a chance, he'll need the "#".
Mark Brittingham