0

我想在 aCheckBox中获取 a 的值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");

            }
        }
    }
4

1 回答 1

0

您应该连接到复选框上的 Checked 事件而不是 click 事件。

你的问题不是很清楚。你能发布更多的代码。例如,什么是 btnRetrieveCheck - 它是实际的复选框吗?请使用您的 XAML 更新问题,以便我们可以查看已设置的绑定。

于 2012-07-09T06:27:51.023 回答