如果系统当前时间超过单选按钮列表项,我想禁用单选按钮列表项。 [英] I want to disable radio button list item if system current time is more than radiobutton list item.
本文介绍了如果系统当前时间超过单选按钮列表项,我想禁用单选按钮列表项。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
i am facing issue i have radiobutton with different time slot and i want to disable radio button list item if system current time is more than radiobutton list item.
I am getting error input string is not in correct format..
What I have tried:
<pre> string id = Request.QueryString["id"];
txtdate.Text = Calendar1.SelectedDate.ToShortDateString();
Calendar1.Visible = false;
// DateTime txtMyDate = DateTime.Parse(txtdate.Text);
SqlConnection cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
string Query = "select slot from appoint where selectdate = @date and doc_id='"+id+"'";
SqlCommand cmd = new SqlCommand(Query, cnn);
cmd.Parameters.AddWithValue("@date", txtdate.Text);
DataTable dtAdmin = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dtAdmin);
if (dtAdmin.Rows.Count > 0)
{
string[] slots = dtAdmin.Rows.OfType<DataRow>().Select(k => k["slot"].ToString()).ToArray();
string time = DateTime.Now.ToString("HH:mm tt");
foreach (ListItem item in RadioButtonList1.Items)
if (slots.Contains(item.Text) && Convert.ToInt32(item.Text) < Convert.ToInt32(time))
{
item.Enabled = false;
}
else
{
item.Enabled = true;
}
}
推荐答案
试试
try
foreach (ListItem item in RadioButtonList1.Items)
{
DateTime dt = DateTime.ParseExact(item.Text, "HH:mm tt", CultureInfo.CurrentCulture);
item.Enabled = DateTime.Now > dt;
}
注意:格式化sql查询字符串易受攻击 SQL Injection [ ^ ]攻击
总是使用参数化查询以防止SQL Server中的SQL注入攻击 [ ^ ]
Note : Formatting the sql Query string is vulnerable to SQL Injection[^] attacks
always use Parameterized queries to prevent SQL Injection Attacks in SQL Server[^]
这篇关于如果系统当前时间超过单选按钮列表项,我想禁用单选按钮列表项。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文