How to populate Radio button and Check box from database?
I have Radio button on my page.I am saving the radio button value in database as 1 or 0 format. My question is when I want to populate the radio button how should i do? Please can anyone help me
EDIT:
DataTable dt 开发者_如何学Python= DataAccess.GetHRInfo(userId);
if((int)dt.Rows[0]["Active"] > 0)
{
optIsActiveYes = 1;
...
Can i assign a value like this?
Considering that you already know how to store value to db I made assumption that you able to read it from DB as well, so:
Radio button will be checked when value is 1
, otherwise reseted, event you'are read wrong value like 2
or -1
EDIT: Update to a comment
DataTable dt = DataAccess.GetHRInfo(userId);
int activeValue;
// by default false
bool optIsActiveYes = false;
if (dt.Rows[0]["Active"] != null
&& Int32.TryParse(dt.Rows[0]["Active"].ToString(), out activeValue))
{
optIsActiveYes = activeValue == 1;
}
Ok It was my mistake . . You can simply use if(radioButton1Value == 1) radioButton1.Checked = true; :)
精彩评论