1

我有一个带复选框的网格。Sometimes, when select row and click ADD button it's not work and debugger show me that haven't selected row. 这是一个代码:

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);
        }
4

1 回答 1

1

希望这可以帮助。这里使用了事件 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;");
        }

    }
于 2012-04-26T07:20:20.307 回答