ASP.NET - 交换布尔值的简单方法?

n20*_*009 1 c# asp.net datagrid

背景:我使用的是ASP.NET 2.0(带有C#),下面的代码嵌入在DataGrid控件中.我的.aspx文件中有以下内容:

        <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>
Run Code Online (Sandbox Code Playgroud)

它应该将布尔值CRS_Included与RadioButtonList绑定.它有效,但顺序相反.是的转为否,没有转为是,我可以看到解决它的唯一方法是交换ListItems的顺序,这将是违反直觉的(单选按钮不应该像No/Yes那样启动,它需要是是/否).

有没有人知道一个快速的方法(最好使用.NET函数)交换0为1,1为0并无缝修复问题?或者,有没有更好的方法来编写SelectedIndex代码?

任何帮助表示赞赏:-)

Jon*_*eet 13

SelectedIndex='<%# 1 - Convert.ToInt32(...) %>
Run Code Online (Sandbox Code Playgroud)

1 - 0 = 1; 1 - 1 = 0.案例互换:)

编辑:可能有更好的方法来处理更一般的问题 - 这只是解决1/0交换的简单方法:)