本文介绍了当复选框被禁用更新不应该做的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个页面,一个是管理,另一个是教师。管理员分配受到教师。教师只只需要选择需要有时间。我的问题是,我不希望为残疾人复选框执行更新查询。我曾尝试低于code,但它更新为残疾复选框了。
使用(SqlConnection的CON2 =新的SqlConnection(ConfigurationManager.ConnectionStrings
[的ConnectionString]。的ConnectionString))
{
的foreach(在Gv1.Rows GridViewRow R){
如果((((
(((复选框)(Gv1.Rows [r.RowIndex] .FindControl(chkHour1)))。经过==真
|| ((复选框)(Gv1.Rows [r.RowIndex] .FindControl(chkHour1)))。经过==假)
|| (((复选框)(Gv1.Rows [r.RowIndex] .FindControl(chkHour2)))。经过==真||((复选框)(Gv1.Rows [r.RowIndex] .FindControl(chkHour2) ))。经过==假)
|| (((复选框)(Gv1.Rows [r.RowIndex] .FindControl(chkHour3)))。经过==真||((复选框)(Gv1.Rows [r.RowIndex] .FindControl(chkHour3) ))。经过==假)
|| (((复选框)(Gv1.Rows [r.RowIndex] .FindControl(chkHour4)))。经过==真||((复选框)(Gv1.Rows [r.RowIndex] .FindControl(chkHour4) ))。经过==假)
|| (((复选框)(Gv1.Rows [r.RowIndex] .FindControl(chkHour5)))。经过==真||((复选框)(Gv1.Rows [r.RowIndex] .FindControl(chkHour5) ))。经过==假)
))))
{
的SqlCommand COMM;
复选框AA;
布尔hour1 =(r.FindControl(chkHour1)作为复选框).Checked;
布尔hour2 =(r.FindControl(chkHour2)作为复选框).Checked;
布尔hour3 =(r.FindControl(chkHour3)作为复选框).Checked;
布尔hour4 =(r.FindControl(chkHour4)作为复选框).Checked;
布尔hour5 =(r.FindControl(chkHour5)作为复选框).Checked;
字符串subject1 = ddlsubj.SelectedValue;
字符串subject2 = ddlsubj.SelectedValue;
字符串subject3 = ddlsubj.SelectedValue;
字符串subject4 = ddlsubj.SelectedValue;
字符串subject5 = ddlsubj.SelectedValue;
字符串DATEDIF = r.Cells [0]。文本;
AA =(复选框)发送;
con2.Open();
COMM =新的SqlCommand();
comm.Connection = CON2;
comm.CommandType = CommandType.Text;
如果(aa.Enabled == FALSE)
{
COMM =新的SqlCommand(更新测试
如果AA = FALSE
当subject1 = CASE WHEN(@ hour1)='假',则空
ELSE @ subject1 END,
subject2 = CASE WHEN(@ hour2)='假',则空
ELSE @ subject2 END,
subject3 = CASE WHEN(@ hour3)='假',则空
ELSE @ subject3 END,
subject4 = CASE WHEN(@ hour4)='假',则空
ELSE @ subject4 END,
subject5 = CASE WHEN(@ hour5)='假',则空
ELSE @ subject5 END,
hour1 = CASE WHEN(@ hour1)='假',则'假'
ELSE'真'END,
hour2 = CASE WHEN(@ hour2)='假',则'假'
ELSE'真'END,
hour3 = CASE WHEN(@ hour3)='假',则'假'
ELSE'真'END,
hour4 = CASE WHEN(@ hour4)='假',则'假'
ELSE'真'END,
hour5 = CASE WHEN(@ hour5)='假',则'假'
ELSE'真正的'到底哪里DATEDIF = @ DATEDIF,CON2);
}
其他
{
COMM =新的SqlCommand(更新测试设置AA =真
当subject1 = CASE WHEN(@ hour1)='假',则空
ELSE @ subject1 END,
subject2 = CASE WHEN(@ hour2)='假',则空
ELSE @ subject2 END,
subject3 = CASE WHEN(@ hour3)='假',则空
ELSE @ subject3 END,
subject4 = CASE WHEN(@ hour4)='假',则空
ELSE @ subject4 END,
subject5 = CASE WHEN(@ hour5)='假',则空
ELSE @ subject5 END,
hour1 = CASE WHEN(@ hour1)='假',则'假'
ELSE'真'END,
hour2 = CASE WHEN(@ hour2)='假',则'假'
ELSE'真'END,
hour3 = CASE WHEN(@ hour3)='假',则'假'
ELSE'真'END,
hour4 = CASE WHEN(@ hour4)='假',则'假'
ELSE'真'END,
hour5 = CASE WHEN(@ hour5)='假',则'假'
ELSE'真正的'到底哪里DATEDIF = @ DATEDIF,CON2);
}
comm.Parameters.AddWithValue(@ subject1,subject1);
comm.Parameters.AddWithValue(@ subject2,subject2);
comm.Parameters.AddWithValue(@ subject3,subject3);
comm.Parameters.AddWithValue(@ subject4,subject4);
comm.Parameters.AddWithValue(@ subject5,subject5);
comm.Parameters.AddWithValue(@ hour1,hour1);
comm.Parameters.AddWithValue(@ DATEDIFDATEDIF);
comm.Parameters.AddWithValue(@ hour2,hour2);
comm.Parameters.AddWithValue(@ hour3,hour3);
comm.Parameters.AddWithValue(@ hour4,hour4);
comm.Parameters.AddWithValue(@ hour5,hour5);
comm.ExecuteNonQuery();
con2.Close();
}
}
}
解决方案
根据您的code如果复选框被禁止,则执行一个查询,如果启用复选框,再执行一次查询
如果(aa.Enabled == FALSE)
{}
其他{}
如果您不希望禁用的复选框去掉执行下面的部分。
如果(aa.Enabled == FALSE)
{}
I have two pages, one is admin and another one is faculty. Admin allocates subject to faculty. Faculty only want to select there required hours only. My issue is that I don't want to perform update query for disabled check box. I have tried the below code, but it is updating for disabled check box too.
using (SqlConnection con2 = new SqlConnection(ConfigurationManager.ConnectionStrings
["ConnectionString"].ConnectionString))
{
foreach (GridViewRow r in Gv1.Rows){
if ((((
(((CheckBox)(Gv1.Rows[r.RowIndex].FindControl("chkHour1"))).Checked == true
|| ((CheckBox)(Gv1.Rows[r.RowIndex].FindControl("chkHour1"))).Checked == false)
|| (((CheckBox)(Gv1.Rows[r.RowIndex].FindControl("chkHour2"))).Checked == true || ((CheckBox)(Gv1.Rows[r.RowIndex].FindControl("chkHour2"))).Checked == false)
|| (((CheckBox)(Gv1.Rows[r.RowIndex].FindControl("chkHour3"))).Checked == true || ((CheckBox)(Gv1.Rows[r.RowIndex].FindControl("chkHour3"))).Checked == false)
|| (((CheckBox)(Gv1.Rows[r.RowIndex].FindControl("chkHour4"))).Checked == true || ((CheckBox)(Gv1.Rows[r.RowIndex].FindControl("chkHour4"))).Checked == false)
|| (((CheckBox)(Gv1.Rows[r.RowIndex].FindControl("chkHour5"))).Checked == true || ((CheckBox)(Gv1.Rows[r.RowIndex].FindControl("chkHour5"))).Checked == false)
))))
{
SqlCommand comm;
CheckBox aa;
bool hour1 = (r.FindControl("chkHour1") as CheckBox).Checked;
bool hour2 = (r.FindControl("chkHour2") as CheckBox).Checked;
bool hour3 = (r.FindControl("chkHour3") as CheckBox).Checked;
bool hour4 = (r.FindControl("chkHour4") as CheckBox).Checked;
bool hour5 = (r.FindControl("chkHour5") as CheckBox).Checked;
string subject1 = ddlsubj.SelectedValue;
string subject2 = ddlsubj.SelectedValue;
string subject3 = ddlsubj.SelectedValue;
string subject4 = ddlsubj.SelectedValue;
string subject5 = ddlsubj.SelectedValue;
string datedif = r.Cells[0].Text;
aa=(CheckBox)sender;
con2.Open();
comm = new SqlCommand();
comm.Connection = con2;
comm.CommandType = CommandType.Text;
if (aa.Enabled==false)
{
comm = new SqlCommand("UPDATE test
SET aa=false
when subject1=CASE WHEN (@hour1)= 'false' THEN NULL
ELSE @subject1 END,
subject2=CASE WHEN (@hour2)= 'false' THEN NULL
ELSE @subject2 END,
subject3=CASE WHEN (@hour3)= 'false' THEN NULL
ELSE @subject3 END,
subject4=CASE WHEN (@hour4)= 'false' THEN NULL
ELSE @subject4 END,
subject5=CASE WHEN (@hour5)='false' THEN NULL
ELSE @subject5 END,
hour1 = CASE WHEN (@hour1)= 'false' THEN 'false'
ELSE 'true' END,
hour2 = CASE WHEN (@hour2)= 'false' THEN 'false'
ELSE 'true' END,
hour3 = CASE WHEN (@hour3)= 'false' THEN 'false'
ELSE 'true' END ,
hour4 = CASE WHEN (@hour4)= 'false' THEN 'false'
ELSE 'true' END ,
hour5 = CASE WHEN (@hour5)= 'false' THEN 'false'
ELSE 'true' END where datedif=@datedif", con2);
}
else
{
comm = new SqlCommand("update test set aa=true
when subject1=CASE WHEN (@hour1)= 'false' THEN NULL
ELSE @subject1 END,
subject2=CASE WHEN (@hour2)= 'false' THEN NULL
ELSE @subject2 END,
subject3=CASE WHEN (@hour3)= 'false' THEN NULL
ELSE @subject3 END,
subject4=CASE WHEN (@hour4)= 'false' THEN NULL
ELSE @subject4 END,
subject5=CASE WHEN (@hour5)='false' THEN NULL
ELSE @subject5 END,
hour1 = CASE WHEN (@hour1)= 'false' THEN 'false'
ELSE 'true' END,
hour2 = CASE WHEN (@hour2)= 'false' THEN 'false'
ELSE 'true' END,
hour3 = CASE WHEN (@hour3)= 'false' THEN 'false'
ELSE 'true' END ,
hour4 = CASE WHEN (@hour4)= 'false' THEN 'false'
ELSE 'true' END ,
hour5 = CASE WHEN (@hour5)= 'false' THEN 'false'
ELSE 'true' END where datedif=@datedif", con2);
}
comm.Parameters.AddWithValue("@subject1",subject1);
comm.Parameters.AddWithValue("@subject2", subject2);
comm.Parameters.AddWithValue("@subject3", subject3);
comm.Parameters.AddWithValue("@subject4", subject4);
comm.Parameters.AddWithValue("@subject5", subject5);
comm.Parameters.AddWithValue("@hour1", hour1);
comm.Parameters.AddWithValue("@datedif", datedif);
comm.Parameters.AddWithValue("@hour2", hour2);
comm.Parameters.AddWithValue("@hour3", hour3);
comm.Parameters.AddWithValue("@hour4", hour4);
comm.Parameters.AddWithValue("@hour5", hour5);
comm.ExecuteNonQuery();
con2.Close();
}
}
}
解决方案
According to your code if check box is disabled you perform one query and if check box enabled you perform another query
if (aa.Enabled==false)
{
}
else{
}
if you don't want to perform on disabled check boxes remove below part
if (aa.Enabled==false)
{
}
这篇关于当复选框被禁用更新不应该做的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!