locked
Checkboxes with submit Button

    Question

  • Hello,

    I am working on the checkboxes for a while. Is there any way to display the "true" in the textblock when we check the multiple answers for a question when the button is clicked?'

    Thanks & Regards

    Ameeruddin.

    Monday, September 01, 2014 10:03 AM

Answers

  •    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
                <CheckBox x:Name="chk1" Content="CheckBox" HorizontalAlignment="Left" Height="86" Margin="22,29,0,0" VerticalAlignment="Top" Width="206" Checked="chk1_Checked" Unchecked="chk1_Unchecked"/>
                <CheckBox x:Name="chk2" Content="CheckBox" HorizontalAlignment="Left" Height="86" Margin="22,277,0,0" VerticalAlignment="Top" Width="206" Checked="chk1_Checked" Unchecked="chk1_Unchecked"/>
                <CheckBox x:Name="chk3" Content="CheckBox" HorizontalAlignment="Left" Height="86" Margin="22,206,0,0" VerticalAlignment="Top" Width="206" Checked="chk1_Checked" Unchecked="chk1_Unchecked"/>
                <CheckBox x:Name="chk4" Content="CheckBox" HorizontalAlignment="Left" Height="86" Margin="22,120,0,0" VerticalAlignment="Top" Width="206" Checked="chk1_Checked" Unchecked="chk1_Unchecked"/>
                <Button Content="Click me" HorizontalAlignment="Left" Height="73" Margin="38,363,0,0" VerticalAlignment="Top" Width="206" Click="Button_Click_1"/>
                <TextBlock Name="tbResult" HorizontalAlignment="Left" Height="32" Margin="45,450,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Width="183"/>
    
            </Grid>
    C#Code

    public partial class MainPage : PhoneApplicationPage { public static List<string> selectedItem { get; set; } // Constructor public MainPage() { InitializeComponent(); selectedItem = new List<string>(); // Sample code to localize the ApplicationBar //BuildLocalizedApplicationBar(); } private void Button_Click_1(object sender, RoutedEventArgs e) { if (selectedItem.Count>=2) { tbResult.Text = "True"; } else { tbResult.Text = "False"; } } private void chk1_Checked(object sender, RoutedEventArgs e) { if (sender !=null) { selectedItem.Add((sender as CheckBox).Name); } } private void chk1_Unchecked(object sender, RoutedEventArgs e) { if (selectedItem.Contains((sender as CheckBox).Name)) { selectedItem.Remove((sender as CheckBox).Name); } } }

    I hope this is what u looking for.



    Ramakant Verma .NET Consultant(Windows Azure, Windows Phone8,Windows 8,ASP.NET,Silverlight)

    • Marked as answer by Ameeruddin Monday, September 01, 2014 11:19 AM
    Monday, September 01, 2014 10:30 AM

All replies

  • every checkbox has its own name so make a textblock and access all the checkboxes by their name and convert their value to textblock like this:

    myTextBlock.Text = "";

    myTextBlock.Text = myCheckBox1.Checked.ToString() +"\n";

    and you expand it and show as much checkboxes value as you want.

    Muhammad Asad.

    Monday, September 01, 2014 10:17 AM
  •    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
                <CheckBox x:Name="chk1" Content="CheckBox" HorizontalAlignment="Left" Height="86" Margin="22,29,0,0" VerticalAlignment="Top" Width="206" Checked="chk1_Checked" Unchecked="chk1_Unchecked"/>
                <CheckBox x:Name="chk2" Content="CheckBox" HorizontalAlignment="Left" Height="86" Margin="22,277,0,0" VerticalAlignment="Top" Width="206" Checked="chk1_Checked" Unchecked="chk1_Unchecked"/>
                <CheckBox x:Name="chk3" Content="CheckBox" HorizontalAlignment="Left" Height="86" Margin="22,206,0,0" VerticalAlignment="Top" Width="206" Checked="chk1_Checked" Unchecked="chk1_Unchecked"/>
                <CheckBox x:Name="chk4" Content="CheckBox" HorizontalAlignment="Left" Height="86" Margin="22,120,0,0" VerticalAlignment="Top" Width="206" Checked="chk1_Checked" Unchecked="chk1_Unchecked"/>
                <Button Content="Click me" HorizontalAlignment="Left" Height="73" Margin="38,363,0,0" VerticalAlignment="Top" Width="206" Click="Button_Click_1"/>
                <TextBlock Name="tbResult" HorizontalAlignment="Left" Height="32" Margin="45,450,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Width="183"/>
    
            </Grid>
    C#Code

    public partial class MainPage : PhoneApplicationPage { public static List<string> selectedItem { get; set; } // Constructor public MainPage() { InitializeComponent(); selectedItem = new List<string>(); // Sample code to localize the ApplicationBar //BuildLocalizedApplicationBar(); } private void Button_Click_1(object sender, RoutedEventArgs e) { if (selectedItem.Count>=2) { tbResult.Text = "True"; } else { tbResult.Text = "False"; } } private void chk1_Checked(object sender, RoutedEventArgs e) { if (sender !=null) { selectedItem.Add((sender as CheckBox).Name); } } private void chk1_Unchecked(object sender, RoutedEventArgs e) { if (selectedItem.Contains((sender as CheckBox).Name)) { selectedItem.Remove((sender as CheckBox).Name); } } }

    I hope this is what u looking for.



    Ramakant Verma .NET Consultant(Windows Azure, Windows Phone8,Windows 8,ASP.NET,Silverlight)

    • Marked as answer by Ameeruddin Monday, September 01, 2014 11:19 AM
    Monday, September 01, 2014 10:30 AM
  • thank u bhai ..............very much
    Monday, September 01, 2014 10:44 AM
  • Hello,

    Can you please provide the source code for the checkboxes which are only correct irrespective of the no of checked boxes.

    Thanks & Regards

    Ameeruddin

    Monday, September 01, 2014 11:19 AM