Hang on. We all missed the real reason this is breaking. ASP.NET
doesn't allow you to put databinding script into tags marked
runat=server. That's why it's breaking even though your expression is
technically correct.
Databound checkbox lists seem to have gotten overlooked when they were
putting ASP.NET together. There's really no way to simply flag a
column to act as the checked/unchecked flag. You have to take care of
this yourself. There are two approaches you can take, via
onItemDatabound, or by building the list by hand.
The first approach involves databinding the list as you've already
done, and hooking up the onItemDatabound event. To pull it off in a
datagrid, you'll need to drop an extra hidden boundcolumn into your
grid that holds the value you're looking for. In the ItemDataBound
handler, you can sniff for that value, find the checkbox and set it.
It's sort of painful, but here's basically how you'll do it:
<asp:datagrid id="dgWhatever" Runat="server"
AutoGenerateColumns="False">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:Label ID="lblIsChecked"
text='<%#DataBinder.Eval(Container.DataItem,"showV ar") %>' Runat=server
Visible=False/>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:CheckBox ID="yourBox" OnDataBinding="yourBox_ItemDataBound"
Runat="server"/>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
protected void yourBox_ItemDataBound(object sender, EventArgs e)
{
CheckBox box = (CheckBox)sender;
DataGridItem item = (DataGridItem)box.NamingContainer;
string isChecked = DataBinder.Eval(item.DataItem, 0).ToString();
if (isChecked == "y")
{
box.Checked = true;
}
else
{
box.Checked = false;
}
}
If you're dealing with an actual CheckBoxList, I find it easier to
simply build the list by hand rather than databinding. To do this,
you'll .clear() the list, then spin through your dataset, .add()ing a
new ListItem for each record, and setting checked state and text for
each.
Anyway, sorry to lead you down the wrong path. Hope this gets you
pointed back in the right direction!
Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/