带有复选框的 ASPxGridView 错误

本文关键字:ASPxGridView 错误 复选框 | 更新日期: 2023-09-27 18:32:13

我有一个带有复选框的网格。有时,当选择行并单击"添加"按钮时,它不起作用,调试器向我显示尚未选择行。这是一个代码:

protected void GridView_CustomCallback(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewCustomCallbackEventArgs e)
    {
        ASPxGridView grid = sender as ASPxGridView;
        List<object> ids = grid.GetSelectedFieldValues("ID");
        if (ids.Count > 0)
        { ......... }
}
SelectAllCheckbox _SelectAll;
    if (!(MyGV.Columns[0] is GridViewCommandColumn))
        {
            _SelectAll = new SelectAllCheckbox() { GridClientInstanceName = MyGV.ClientInstanceName };
            Common.AddCommandColumn(MyGV, 0, _SelectAll);
        }

带有复选框的 ASPxGridView 错误

希望这有帮助。这里使用事件 RowDataBound。

private string chkGridColHeaderId = string.Empty;
protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header)
        {
            CheckBox chkAll = (CheckBox)e.Row.FindControl("chkSelectAll");
            chkAll.Attributes.Add("onclick", "SelectAll(this.checked)");
            chkGridColHeaderId = chkAll.ClientID;
        }
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            CheckBox chkSelect = (CheckBox)e.Row.FindControl("chkSelect");
            chkSelect.Attributes.Add("onclick", "if(!this.checked)document.getElementById('" + chkGridColHeaderId + "').checked = false;");
        }
    }