Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ASP.NET-交换布尔值的简单方法?_C#_Asp.net_Datagrid - Fatal编程技术网

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

C# ASP.NET-交换布尔值的简单方法?,c#,asp.net,datagrid,C#,Asp.net,Datagrid,背景:我正在使用ASP.NET2.0和C,下面的代码是 嵌入在DataGrid控件中。 我的.aspx文件中有以下内容: <ASP:TEMPLATECOLUMN HeaderText="Includes CRS Statement?"> <ITEMTEMPLATE> <asp:RadioButtonList id="rblSCIncludesCRSStatement" runat=

背景:我正在使用ASP.NET2.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>
它应该绑定RadioButtonList中包含的布尔值CRS_。它起作用,但顺序相反。Yes变为no,no变为Yes,我能看到的唯一解决方法是交换ListItems的顺序,这将是违反直觉的单选按钮不应该像no/Yes那样启动,它需要是Yes/no

有没有人知道一种更适合使用.NET函数的快速方法来将0替换为1、1替换为0并无缝修复问题?或者,有没有更好的方法来编写SelectedIndex代码

感谢您的帮助:-

SelectedIndex='<%# 1 - Convert.ToInt32(...) %>
1-0=1;1 - 1 = 0. 交换的案例:

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

1-0=1;1 - 1 = 0. 交换的案例:


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

为什么不使用SelectedValue属性而不是SelectedIndex.?

为什么不使用SelectedValue属性而不是SelectedIndex.?

您尝试过使用SelectedValue而不是SelectedIndex吗选择索引


从MSDN中,SelectedValue属性还可用于通过将列表控件中的项设置为该项的值来选择该项。

是否尝试使用SelectedValue而不是SelectedIndex


从MSDN中,SelectedValue属性还可以用于通过将列表控件中的项设置为该项的值来选择该项。

duh为什么我没有想到:我想到了使用数学函数的想法,但我想到了mod或其他什么。。。说真的,虽然是个好主意!duh为什么我没有想到:我想到了使用数学函数的想法,但我在想mod或其他什么。。。说真的,虽然是个好主意!如果你喜欢乔恩的回答,你应该把它标为接受!如果你喜欢乔恩的回答,你应该把它标为接受!