表值获取具有性别列的男性和女性,根据男性单选按钮将检查其他女性检查 [英] Table values fetch which is having gender column as Male and female, according to male radio button will check else female check

查看:120
本文介绍了表值获取具有性别列的男性和女性,根据男性单选按钮将检查其他女性检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将表格数据提取到数据集中,这也是持有性别值,我需要检查条件,如果单选按钮数据集列=男性然后选择男性单选按钮,

这是我的代码。 ..需要支持

I fetch a table data into dataset, which is holding gender values also, I need to check the condition if radio button dataset column=male then select male radio button,
this is my code...Need bit of support

if (ds.Tables[0].Rows[i]["Gender"].ToString() == "M")
                    {
                        rbtmale.Checked = true;
                    }
                    else
                    {
                        rbtfemale.Checked = true;
                    }

推荐答案

该代码没有任何问题。



Radiobuttons的设计使得自动每次只能检查一个容器中的一个。因此,只需设置Checked值即可完全有效。



如果这些是表单上唯一的RadioButtons,则无需将它们放入组框或任何其他容器。我确实将radiobuttons放入容器中以供优先使用,因为如果以后添加任何内容会更容易,它们需要在表单上重新定位,或者如果Winforms RadioButtonList控件出现则需要更换它们。



如果他们没有按照您的预期行事那么它可能是三件事之一



There is nothing wrong with that code.

Radiobuttons are designed so that automatically only one per container can be Checked at any one time. So it is perfectly valid to just set the Checked value as you have done.

If these are the only RadioButtons on the form then there is no need to put them into a groupbox or any other container. I do put radiobuttons into a container for preference as it makes it easier if anything is added later, they need to be re-sited on the form, or if they need to be replaced if a Winforms RadioButtonList control comes along.

If they are not behaving as you expected then it can be one of three things



  1. (如果两个RB都显示为已选中)您已将RadioButtons放置在表单上的两个单独的容器控件中。确保它们属于同一个。
  2. (如果总是检查女性RB的情况)您的数据集实际上并不在性别列中包含M。
  3. (如果检查不同的RB到您期望的那个)如果此代码在循环中,您将只显示最后一条记录的性别


你好,

首先这样做,采取radiobutton列表而不是性别的单选按钮,因为用户可以选择MALE或FEMALE,不能同时选择:)

所以请使用radiobutton列表并试试这个,



Hello,
first do this ,take radiobutton list instead of radio buttons for gender because user could select either MALE or FEMALE , can't be select BOTH :)
so take radiobutton list and try with this ,

<asp:RadioButtonList ID="radGender" runat="server" RepeatDirection="Horizontal" Width="75%">
                      <asp:ListItem Value="M">Male</asp:ListItem>
                      <asp:ListItem Value="F">Female</asp:ListItem><br />
                  </asp:RadioButtonList>







if (ds.Tables[0].Rows[i]["Gender"].ToString() == "M")
                    {
                        radGender.SelectedValue = "M";
                    }
                    else
                    {
                        radGender.SelectedValue = "F";
                    }



如果它适用于你,请在此处确认。

谢谢。


If its work for you , acknowledge here.
Thank you.


在Windows窗体中,

使用GROUP BOX并在其中拖动2个单选按钮,给出id和值,

所以你将一次选择任何一个。

然后在代码后面写代码。

In windows form ,
take GROUP BOX and drag 2 radio button in it , give id and values ,
so u will select any one at a time.
then in code behind write code.
if (ds.Tables[0].Rows[i]["Gender"].ToString() == "M")
                    {
                        radMale.SelectedValue = "M";
                    }
                    else
                    {
                        radFemale.SelectedValue = "F";
                    }





:)

谢谢。



:)
Thank you.


这篇关于表值获取具有性别列的男性和女性,根据男性单选按钮将检查其他女性检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆