Background: I am using ASP.NET 2.0 (with C#) and the code below is embedded in a DataGrid control. I have the following in my .aspx file:
<ASP:TEMPLATECOLUMN HeaderText="Includes CRS Statement?">
<ITEMTEMPLATE>
<asp:RadioButtonList id="rblSCIncludesCRSStatement" runat="server" RepeatDirection="Horizontal"
SelectedIndex='<%# Convert.ToInt32(DataBinder.Eval(Container, "DataItem.CRS_Included")) %>'
DataValueField="CRS_Included" RepeatLayout="Flow">
<asp:ListItem value="true" selected="true">Yes</asp:ListItem>
<asp:ListItem value="false">No</asp:ListItem>
</asp:RadioButtonList>
</ITEMTEMPLATE>
</ASP:TEMPLATECOLUMN>
<ASP:BOUNDCOLUMN visible="false" HeaderText="IncludesCRSStatement" DataField="CRS_Included"></ASP:BOUNDCOLUMN>
It is supposed to bind the boolean value CRS_Included with the RadioButtonList. It works, but in reverse order. Yes is turned to no, no is turned to yes, and the only way I can see to fix it is swap the order of the ListItems, which would be counterintuitive (Radio buttons shouldn't start like No/Yes, it needs to be Yes/No).
Does anyone know a quick way (preferably using .NET functions) to swap the 0 for 1, 1 for 0 and fix the problem seamlessly? Or, is there a better way to write the SelectedIndex code?
Any help is appreciated :-)