【发布时间】:2018-09-26 00:20:21
【问题描述】:
我有几个带有checkboxes control 的gridview 列有一个autopostback='true' 来更新数据库。
当我选中其中一个复选框时,整行都会更新,这让我很沮丧。
我正在尝试查找列的checkbox control不是整个gridview
我知道Mycheckbox.checked 总是正确的,因为它查看“所有的检查值”但是我希望它只查看指定的列
有没有可能做类似Checkbox MyCheckbox = findcontrol(*MyColumn*)......
protected void myCheckBox_OnCheckedChange(object sender, EventArgs e)
{
CheckBox myCheckBox = (CheckBox)sender;
GridViewRow row = (GridViewRow)myCheckBox.NamingContainer;
bool status = myCheckBox.Checked;
string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
using (SqlConnection con = new SqlConnection(CS))
{
SqlCommand cmd = new SqlCommand("sp_tblPlanningChecked", con);
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@PlanningID", row.Cells[1].Text);
cmd.Parameters.AddWithValue("@ThisWeekMinus2", myCheckBox.Checked);
cmd.Parameters.AddWithValue("@ThisWeekMinus1", myCheckBox.Checked);
cmd.Parameters.AddWithValue("@ThisWeek", myCheckBox.Checked);
cmd.Parameters.AddWithValue("@ThisWeekPlus1", myCheckBox.Checked);
cmd.Parameters.AddWithValue("@ThisWeekPlus2", myCheckBox.Checked);
cmd.Parameters.AddWithValue("@ThisWeekMinus3", myCheckBox.Checked);
cmd.Parameters.AddWithValue("@ThisWeekMinus4", myCheckBox.Checked);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
【问题讨论】:
-
我已经阅读了你的问题几次,但我仍然不明白你想要做什么。所以你有
column1并且想要得到所有CheckBoxes 是Checked == true? -
这完全令人困惑。在您的图片中有 7 列,每列有 10 个
Checkboxes。 -
这到底是什么意思:
iim trying to find out how i can use "findcontrol" of a column insted of using myCheckBox as the only checkbox sender?所以你想找到一个控件?请回答Yes或No,以保持简单。此外,您不想使用每个 comboBoxs sender in its event as a convertedComboBox` 事件,那您还想使用什么?您的总体目标是什么? -
好吧,假设我们在
Columncolumn1。现在您想获取 column1 中所有已检查的CheckBoxes吗?Yes或No? -
但是现在你谈论一个(在这个例子中简化 one 这个)列。但是这一列有相当多的复选框。那么,当有不同的 CheckBox 带有已选中/未选中时,您如何想象得到真/假?
标签: c# asp.net gridview checkbox oncheckedchanged