简体   繁体   English

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

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

I'm saving the checked radio button number in the database. 我将选中的单选按钮号保存在数据库中。 If the column contains the number then the radio button shows it's checked and the if the column contains null/empty then the radio button is unchecked. 如果该列包含数字,则单选按钮显示它已选中;如果该列包含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;
}

but it gives always empty value. 但它始终提供空值。 plz give the solution on it 请给解决方案

Look of empty string where you expect null in datatable, secondly you are passing string in switch which is check but using int value you might need case "1": instead of case 1: 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