我想根据数据库中的值检查单选按钮 [英] i want to checked the radio button according to value in database

查看:54
本文介绍了我想根据数据库中的值检查单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

if (dt.Rows[0]["Gender"] == "Male")
    rdomale.Checked = true;
else
    rdofemale.Checked = true;

推荐答案

您调试了吗?
请注意,等于运算符==区分大小写:如果在数据库中Gender存储为"male",则将出现不匹配的情况(然后可以使用String.Equals方法,请参见> Stack Overflow上是否存在C#不区分大小写的等于运算符?" [^ ]).
Did you debug it?
Note that equal operator == is case sensitive: if in the database Gender is stored as "male" then you get a mismatch (you may then use the String.Equals method, see "Is there a C# case insensitive equals operator?" at Stack Overflow[^]).


您必须将数据表中的数据转换为字符串

尝试这种方式:
You have to convert data from DataTable into string

try this way:
if (dt.Rows[0]["Gender"].ToString().Trim().ToLower() == "male")
    rdomale.Checked = true;
else
    rdofemale.Checked = true;



请注意男性"和男性"的变化,因为我已经使用ToLower()进行了准确的比较.



note the change in "Male" and "male", because i have used ToLower() for accurate comparison.


这篇关于我想根据数据库中的值检查单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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