Пример #1
0
    protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == "alpha" || e.CommandName == "NoFilter")
        {
            String value = null;
            switch (e.CommandName)
            {
            case ("alpha"):
            {
                value = string.Format("{0}%", e.CommandArgument);
                break;
            }

            case ("NoFilter"):
            {
                value = "%";
                break;
            }
            }
            ObjectDataSource1.SelectParameters["DistrictName"].DefaultValue = value;
            ObjectDataSource1.DataBind();
            RadGrid1.Rebind();
        }
        else if (e.CommandName == "QuickUpdate")
        {
            string DistrictID, Priority, IsAvailable;
            var    oDistrict = new District();

            foreach (GridDataItem item in RadGrid1.Items)
            {
                DistrictID  = item.GetDataKeyValue("DistrictID").ToString();
                Priority    = ((RadNumericTextBox)item.FindControl("txtPriority")).Text.Trim();
                IsAvailable = ((CheckBox)item.FindControl("chkIsAvailable")).Checked.ToString();

                oDistrict.DistrictQuickUpdate(
                    DistrictID,
                    Priority,
                    IsAvailable);
            }
        }
        else if (e.CommandName == "PerformInsert" || e.CommandName == "Update")
        {
            var command = e.CommandName;
            var row     = command == "PerformInsert" ? (GridEditFormInsertItem)e.Item : (GridEditFormItem)e.Item;

            string strIsAvailable = ((CheckBox)row.FindControl("chkIsAvailable")).Checked.ToString();

            if (e.CommandName == "PerformInsert")
            {
                ObjectDataSource1.InsertParameters["IsAvailable"].DefaultValue = strIsAvailable;
            }
            else
            {
                ObjectDataSource1.UpdateParameters["IsAvailable"].DefaultValue = strIsAvailable;
            }
        }
        else if (e.CommandName == "DeleteSelected")
        {
            var    oDistrict = new District();
            string errorList = "", DistrictName = "";

            foreach (GridDataItem item in RadGrid1.SelectedItems)
            {
                try
                {
                    var DistrictID = item.GetDataKeyValue("DistrictID").ToString();
                    DistrictName = item["DistrictName"].Text;
                    oDistrict.DistrictDelete(DistrictID);
                }
                catch (Exception ex)
                {
                    lblError.Text = ex.Message;
                    if (ex.Message == ((int)ErrorNumber.ConstraintConflicted).ToString())
                    {
                        errorList += ", " + DistrictName;
                    }
                }
            }
            if (!string.IsNullOrEmpty(errorList))
            {
                e.Canceled = true;
                string strAlertMessage = "Quận/Huyện <b>\"" + errorList.Remove(0, 1).Trim() + " \"</b> đang chứa Phường/Xã.<br /> Xin xóa Phường/Xã trong Quận/Huyện này hoặc thiết lập hiển thị = \"không\".";
                lblError.Text = strAlertMessage;
            }
        }
    }