我想在CheckBox
中获得GridView
的值。我可以使用事件GridView
绑定RowDataBound
。但在Click
Button
事件CheckBox
事件中CheckBox
的值始终为假,即使我选中了 protected void GridView1_RowDatabound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList dddate = (DropDownList)e.Row.FindControl("DdlDate");
DropDownList ddYear = (DropDownList)e.Row.FindControl("DdlYear");
for (int i = System.DateTime.Now.Year; i > (System.DateTime.Now.Year) - 100; i--)
ddYear.Items.Add(Convert.ToString(i));
for (int i = 1; i < 32; i++)
dddate.Items.Add(Convert.ToString(i));
}
}
protected void btnRetrieveCheck_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox cb = (CheckBox)row.FindControl("chkSel");
if (cb != null && cb.Checked)
{
DropDownList dddate = (DropDownList)row.FindControl("DdlDate"); //Bind data to the GridView control.
DropDownList ddYear = (DropDownList)row.FindControl("DdlYear");
DropDownList ddmonth = (DropDownList)row.FindControl("DdlMonth");
}
}
}
。
代码背后:
{{1}}
答案 0 :(得分:0)
您应该选中复选框上的Checked事件而不是click事件。
你的问题不是很清楚。你可以发布更多的代码吗?例如,什么是btnRetrieveCheck - 它是实际的复选框吗?请使用您的XAML更新问题,以便我们了解具体的绑定。