如何从数据库到单选按钮获取所选值 [英] How do I Get The Selected Value From Database To Radio Button

查看:217
本文介绍了如何从数据库到单选按钮获取所选值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小型的网络应用程序但是当我检索要编辑的数据时,我可以检索每个单元格到那里文本框但我无法获得单选按钮值



I have a small web application but when i retrieve data to edit ,i can retrieve every cell to there textbox but i can't get radio button value

SqlDataReader dr;

dr = comm.ExecuteReader();
if (dr.HasRows == true)
{
    dr.Read();
    RegionNameTextBox.Text = dr["RegionNameEn"].ToString();
    StatusRadioButtonList.Text = dr["RegionStatus"].ToString();
    dr.Close();
    comm.Parameters.Clear();
}

推荐答案

看起来你正在尝试分配一个选中或未选中的单选按钮。< br $> b $ b

Looks like you are trying to assign a Radio Button checked or not-checked.

//To set the text of the Radiobutton
StatusRadioButtonList.Text = "Selected value";

//Tot set checked or not
StatusRadioButtonList.Checked = true;

//If you are trying to check and set more than 1 Radio button
//All the radio button should of same group
if (rdoStatusRadioButtonListA.Text.ToString().Equals("One"))
        {
            rdoStatusRadioButtonListA.Checked = true;
        }
else  {
            rdoStatusRadioButtonListA.Checked = false;
            rdoStatusRadioButtonListB.Checked = true;
     }





如果这个答案没有解决您的问题,请告诉我。我将提供更详细的信息。



Let me know if this answer doesn't solve your problem. I will provide in much detail.


如果您从数据库中检索Active或Inactive值,您可以使用以下代码,

If you retrieving the Active or Inactive value from database you can use following code,
if(dr["RegionStatus"].ToString()=="Active")
{
   StatusRadioButtonList.Items[0].Selected=true;
   StatusRadioButtonList.Items[1].Selected=false;
}
else if(dr["RegionStatus"].ToString()=="Inactive")
{
   StatusRadioButtonList.Items[0].Selected=false;
   StatusRadioButtonList.Items[1].Selected=true;
}


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

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