复选框值仅更新数据库中的N. [英] Checkbox value only updating N in database
本文介绍了复选框值仅更新数据库中的N.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
protected void Button7_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in GridView1.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
if (Session["Role_Name"] != null && !string.IsNullOrEmpty(Session["Role_Name"].ToString()))
{
CheckBox chkAdd = (row.Cells[1].FindControl("CheckBox1") as CheckBox);
CheckBox chkEdit = (row.Cells[2].FindControl("CheckBox2") as CheckBox);
CheckBox chkView = (row.Cells[3].FindControl("CheckBox3") as CheckBox);
CheckBox chkDelete = (row.Cells[4].FindControl("CheckBox4") as CheckBox);
// string strID = row.Cells[0].Text;
string Pages = row.Cells[0].Text;
con.Open();
string query = "Update Role1 set [Add]='" + (chkAdd.Checked == true ? 'Y' : 'N') + "', [View]='" + (chkView.Checked == true ? 'y' : 'N') + "' ,[Edit]='" + (chkEdit.Checked == true ? 'y' : 'N') + "' ,[Delete]='" + (chkDelete.Checked == true ? 'y' : 'N') + "' where Pages ='" + Pages + "' and Role_Name='" + Session["Role_Name"].ToString() + "'";
SqlCommand cmd = new SqlCommand(query, con);
cmd.ExecuteNonQuery();
populateGridview();
con.Close();
}
}
}
}
这是我的代码。在这种情况下,当我选中复选框
Hi, This is my code. In this case checkbox value N is storing in database when i checked the checkbox
推荐答案
这篇关于复选框值仅更新数据库中的N.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文