我有两个单选按钮:是和否。
我将选择(0或1)的值存储到SQL数据库中。现在,我想在使用数据集加载表单时,将数据库中的那些单选按钮的值显示给用户。 这是我的代码:
public void LoadRequestInfo()
{
CommonCollection c = new CommonCollection();
var CTS = c.COMPTRACKERCONNECTIONSTRING();
var CTS_conn = new SqlConnection(CTS.ConnectionString);
try
{
SqlCommand cmd = new SqlCommand("CTS_GetRequest", CTS_conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@ID", "100221"));
cmd.Parameters.Add(new SqlParameter("@RequestId", "CD558017-8CEA-496D-9537-A53E1E2BA8AD"));
cmd.Parameters.Add(new SqlParameter("@UserID", Microsoft.SharePoint.SPContext.Current.Web.CurrentUser.ID));
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
CTS_conn.Open();
da.Fill(ds);
CTS_conn.Close();
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
txtTitle.Text = ds.Tables[0].Rows[0][17].ToString();
drpProperty.SelectedItem.Text = ds.Tables[0].Rows[0][2].ToString();
drpCategory.SelectedValue = ds.Tables[0].Rows[0][3].ToString();
rdYes.Checked = ds.Tables[0].Rows[0][12].ToString(); //Here is the part I have problem.
rdNo.Checked = ds.Tables[0].Rows[0][14].ToString();
}
}
}
答案 0 :(得分:0)
我能够显示单选按钮的结果:
Boolean IsYes = Boolean.Parse(ds.Tables[0].Rows[0][12].ToString());
if (IsYes == true)
{
rdYes.Checked = true;
txtPenalty.Visible = true;
}
else if (IsYes == false)
{
rdNo.Checked = true;
txtPenalty.Visible = false;
}