sisibest

导航

使用LINQ取得已选中的CheckBox .

1. IList<string> FeildList = (from ListItem li in cblFeild.Items where li.Selected select li.Value).ToList();

            string[] UpperIDs = FeildList.ToArray<String>();

 

2.  <toolkit:WrapPanel Name="wrpContainer" >

                   <CheckBox Content="CheckBox1" Height="16" Name="checkBox1" Margin="20" FontSize="14" />

                  <CheckBox Content="CheckBox2" Height="16" Name="checkBox2" Margin="20" FontSize="14" />

                  <CheckBox Content="CheckBox3" Height="16" Name="checkBox3" Margin="20" FontSize="14" />

                  <CheckBox Content="CheckBox4" Height="16" Name="checkBox4" Margin="20" FontSize="14"/>

                  <CheckBox Content="CheckBox6" Height="16" Name="checkBox6" Margin="20" FontSize="14" />

                  <CheckBox Content="CheckBox7" Height="16" Name="checkBox7" Margin="20" FontSize="14" />

                  <CheckBox Content="CheckBox8" Height="16" Name="checkBox8" Margin="20" FontSize="14" />

                  <CheckBox Content="CheckBox9" Height="16" Name="checkBox9" Margin="20" FontSize="14" />

                   <CheckBox Content="CheckBox10" Height="16" Name="checkBox10" Margin="20" FontSize="14" />

</toolkit:WrapPanel>

 

 

 

  var checkedItems = wrpContainer.Children.OfType<CheckBox>().Where( c => c.IsChecked == true );

  MessageBox.Show( string.Format( "有 {0}个选项已选择 " , checkedItems.Count().ToString() ) );

 

posted on 2013-03-19 17:51  sisibest  阅读(184)  评论(0编辑  收藏  举报