繁体   English   中英

查找从C#中的数据集中检查哪个单选按钮

[英]Find which radio button is checked from dataset in c#

我将选中的单选按钮号保存在数据库中。 如果该列包含数字,则单选按钮显示它已选中;如果该列包含null / empty,则未选中该单选按钮。

int chk;
if(DBNull.Value.Equal(dataset.table["TableName"].Rows[i][9].ToSting()))

{ 

     chk = dsData.Tables["Option"].Rows[n][9].ToString();

     switch(chk)
     {
         case 1: radioButton1.Checked=true;
         break;
         .
         .
         .
         case 4: radioButton4.Checked=true;
         break;
     }
}

else

{
      radioButton1.Checked=false; . . .  radioButton4.Checked=false;
}

但它始终提供空值。 请给解决方案

empty string where you expect null在数据表中为empty string where you expect nullempty string where you expect null查找内容,其次,您在switch中传递要检查的字符串,但使用int值时,可能需要case "1": instead of case 1:

if(dataset.table["TableName"].Rows[i][9].ToSting() != "")
{     
     chk = dsData.Tables["Option"].Rows[n][9].ToString();    
     switch(chk)
     {
         case 1: radioButton1.Checked=true;
         break;
         .
         .
         .
         case 4: radioButton4.Checked=true;
         break;
     }
}    
else    
{
      radioButton1.Checked=false; . . .  radioButton4.Checked=false;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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