DEV GRIDVIEW 过滤行数值型列输入非数字字符时出现错误提示:数据类型不匹配的解决方法

本文介绍了一种解决DEVGRIDVIEW过滤行数值型列输入非数字字符时出现的数据类型不匹配错误的方法。通过判断ASPxGridView中是否有可见记录来决定是否处理过滤行下拉列表,从而避免了错误提示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

DEV GRIDVIEW 过滤行数值型列输入非数字字符时出现错误提示:数据类型不匹配。分析得出:如果在数据值型列过滤控件中输入非数值型内容时,不会查出记录,根据这一情况在ASPxGridView1_AutoFilterCellEditorInitialize事件,首先判断ASPxGridView1中是否有可见记录,如果没有则不处理过滤行下拉列表,否则,处理!这样就完美的解决了这个问题。
如下所示:

protected void ASPxGridView1_AutoFilterCellEditorInitialize(object sender, ASPxGridViewEditorEventArgs e)
        {
            List<string> ls = new List<string> { "年度", "区分合作", "合作备注", "作废", "管理员", "主挂罐", "号牌号码", "关联主号牌", "人员", "企业", "分类明细", "业务分类", "区分业务", "经手人", "收付", "收付说明", "结算客户", "票据说明", "票据客户", "单位名称", "有效状态", "关键列", "终止标记" };
            if (ls.Contains(e.Column.FieldName))
            {
                string gltj_str;
                //用DEV过滤条件转换方法转换为MsSQL格式的过滤条件
                ASPxGridView grd = HttpContext.Current.Session["fjyw_grd"] as ASPxGridView;

                if (grd.VisibleRowCount > 0)//首先判断ASPxGridView1中是否有可见记录,如果没有则不处理过滤行下拉列表,否则,处理!
                {
                    CriteriaOperator op = CriteriaOperator.Parse(grd.FilterExpression);
                    gltj_str = CriteriaToWhereClauseHelper.GetMsSqlWhere(op);


                    if (!gltj_str.Contains("Null"))
                    {

                        if (gltj_str != "" && !gltj_str.Contains("where"))
                        {
                            gltj_str = " where " + gltj_str + " and convert(varchar(20),业编时间,23)>='" + start_time.ToString("yyyy-MM-dd") + "' and convert(varchar(20),业编时间,23)<='" + end_time.ToString("yyyy-MM-dd") + "'";
                        }
                        else
                        {
                            gltj_str = " where convert(varchar(20),业编时间,23)>='" + start_time.ToString("yyyy-MM-dd") + "' and convert(varchar(20),业编时间,23)<='" + end_time.ToString("yyyy-MM-dd") + "'";
                        }

                    }
                    e.Column.Settings.FilterMode = ColumnFilterMode.DisplayText;
                    ASPxComboBox combo = e.Editor as ASPxComboBox;
                    combo.ValueType = typeof(string);
                    combo.DropDownStyle = DropDownStyle.DropDown;
                    DataTable temp_dt = SqlHelper.ExecuteDataTable("select distinct " + e.Column.FieldName + " from 附加业务 " + gltj_str, new SqlParameter[] { });
                    foreach (DataRow dr in temp_dt.Rows)
                    {
                        combo.Items.Add(dr[e.Column.FieldName].ToString());
                    }
                }
                else//如果没有可见行则清空过滤行下拉列表
                {
                    ASPxComboBox combo = e.Editor as ASPxComboBox;
                    combo.ValueType = typeof(string);
                    combo.DropDownStyle = DropDownStyle.DropDown;
                    combo.Items.Clear();
                }
            }
        }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值