How to set radio button in datagrid?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi experts,

I have a little problem with datagrid needing your expertise.

In database, I have a column called "Active" which has only 2 values "Yes"
and "No". In my application, I want to show the value in redio format so that
user can simply click "Yes" or "No" to switch value. But I don't know how to
set the data format for a column in the dataset. Can you share ms some of
your experience about it?

Thanks,

Karl
 
Karl,

I assume that you don't have the option of handling and storing your value
as a boolean (bit in SQL Server) in your database which is, IMHO, the best
thing to do.

If that is correct then, alternatively, you could set the Checked property
of the RadioButton to the result of the following statement:

string.Compare(stringDatabaseValue, "Yes", true) == 0;

or use a case statement in the stored procedure that fills your dataset so
that you can return a 1 or 0 for Yes or No and then set RadioButton.Checked
to

Convert.ToBoolean(intDatabaseValue);

In your Update stored procedure use a case statement again like this:

CASE WHEN @ButtonValue = 1 THEN 'Yes' ELSE 'No'

Another option is to add a DataColumn to the table you're using with the
DataType property set to System.Type.GetType("System.Boolean"). Then
iterate through your rows and set the new boolean column using the
statements I showed above.

The point is, the data you're talking about is not a string, it is a
boolean: Yes/No... Two states. You're manipulating it as a boolean: Checked
= true/false... Two states. Yet, you're storing it as a string. That is
always going to cause you a problem. Store your data according to what it
is and let the UI, in this case the labels on your RadioButtons handle the
user interface portion, as it is designed to do.

HTH

DalePres
MCAD, MCDBA, MCSE
 
Back
Top