简体   繁体   中英

always getting values of radiobuttonlist's server side in WPF

Below is my XAML page code for radiobuttonlist:

<Label Content="Name" HorizontalAlignment="Left" Height="30" VerticalAlignment="Top" Width="105" Margin="10,14,0,0"/>
    <Label Content="Age" HorizontalAlignment="Left" Height="30" VerticalAlignment="Top" Width="105" Margin="10,66,0,0"/>
    <Label Content="Gender" HorizontalAlignment="Left" Height="30" VerticalAlignment="Top" Width="105" Margin="10,115,0,0"/>
    <GridSplitter HorizontalAlignment="Left" Height="146" Margin="167,10,0,0" VerticalAlignment="Top" Width="5"/>
    <TextBox x:Name="txtName" HorizontalAlignment="Left" Margin="221,16,0,396"
             TextWrapping="Wrap" Width="120">
    </TextBox>
    <TextBox x:Name="txtAge" HorizontalAlignment="Left" Height="23" Margin="221,73,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
    <Button Name="btnSave" Style="{StaticResource Allbtn}" Content="Save" HorizontalAlignment="Left" Margin="53,190,0,0" VerticalAlignment="Top" Width="100" Height="32" Click="btnSave_Click"/>
    <Button x:Name="btnExit" Style="{StaticResource Allbtn}" Content="Exit" HorizontalAlignment="Left" Margin="326,191,0,0" VerticalAlignment="Top" Width="100" Height="32" Click="btnExit_Click" Grid.ColumnSpan="2"/>
    <Grid HorizontalAlignment="Left" Name="grdGender" Height="41" Margin="221,115,0,0" VerticalAlignment="Top" Width="223" Grid.ColumnSpan="2">
        <ListBox Name="rdoGender" Margin="0,0,100,0">
            <RadioButton GroupName="rdoGender" Tag="M" Content="Male"/>
            <RadioButton GroupName="rdoGender" Tag="F" Content="Female"/>
        </ListBox>
    </Grid>
    <Button x:Name="btnClear" Style="{StaticResource Allbtn}" Content="Clear" HorizontalAlignment="Left" Margin="198,191,0,0" VerticalAlignment="Top" Width="100" Height="32" Click="btnClear_Click"/>
    <Button x:Name="btnTestWCF" Style="{StaticResource Allbtn}" Content="Test WCF" HorizontalAlignment="Left" Margin="221,244,0,0" VerticalAlignment="Top" Width="100" Height="32" Click="btnTestWCF_Click"/>

And below is code for Serverside to get selected value:

vEmployeeMasterSC.Gender = rdoGender.IsEnabled != true ? rdoGender.Tag.ToString() : "";

I am unable to get the selected radiobutton list's value to save into database.

Give each radio button a name and use IsChecked on the RadioButton to determine which one is checked:

<RadioButton x:Name="rdoFemale" GroupName="rdoGender" Tag="M" Content="Male"/>
<RadioButton x:Name="rdoMale" GroupName="rdoGender" Tag="M" Content="Male"/>

vEmployeeMasterSC.Gender = rdoMale.IsChecked == true ? "Male" : "Female";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM