SpreadAsp.Net版整数型Cell最大最小值Check
本帖最后由 Catsou55 于 2018-4-25 10:26 编辑整数型单元格的默认可以输入任何字符,为了实现只能输入数字的功能,需要结合InputMan的验证控件GcCharacterTypeValidator。代码如下所示,数字输入功能实现了,可是数值1~999的范围check失效了。麻烦帮看看问题出在哪里。
Dim intCell As New IntegerCellType
intCell.MinimumValue = 1
intCell.MaximumValue = 999
Dim GcCharacterTypeValidator1 As New GcCharacterTypeValidator
GcCharacterTypeValidator1.ID = "dataTypeValidator1"
GcCharacterTypeValidator1.ValidateOnInput = True
GcCharacterTypeValidator1.CharacterSet = "9"
GcCharacterTypeValidator1.ValidatorActionID = "GcValidatorAction1"
Dim valProc As New ValueProcess
valProc.ValueProcessOption = ValueProcessOption.Restore
GcValidatorAction1.DefaultActions.Add(valProc)
intCell.Validators.Add(GcCharacterTypeValidator1)
建议您直接发可直接运行的Demo,这样处理快很多。 <%@ Page Language="VB" Inherits="System.Web.UI.Page" %>
<%@ Register assembly="GrapeCity.Web.Input.v100, Version=10.0.4000.2012, Culture=neutral, PublicKeyToken=c3bd7c1dccef5128" namespace="GrapeCity.Web.Input.IMValidators" tagprefix="im_validator" %>
<%@ Register assembly="GrapeCity.Web.Input.v100, Version=10.0.4000.2012, Culture=neutral, PublicKeyToken=c3bd7c1dccef5128" namespace="GrapeCity.Web.Input.IMExtenders" tagprefix="im_extenders" %>
<!DOCTYPE html>
<script language="VB" type="text/VB" runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
InitVaSpread1()
End Sub
Private Sub InitVaSpread1()
FpSpread1.EditModeReplace = True
FpSpread1.ProcessTab = True
FpSpread1.HorizontalScrollBarPolicy = ScrollBarPolicy.Never
FpSpread1.VerticalScrollBarPolicy = ScrollBarPolicy.Always
FpSpread1.ActiveSheetView.DefaultRowHeight = 37
FpSpread1.ActiveSheetView.RowCount = 4
FpSpread1.ActiveSheetView.ColumnCount = 2
FpSpread1.ColumnHeader.Cells(0, 0).Value = "Col1"
FpSpread1.ColumnHeader.Cells(0, 1).Value = "Col2"
FpSpread1.ActiveSheetView.Columns(0).Width = 100
FpSpread1.ActiveSheetView.Columns(1).Width = 100
FpSpread1.ActiveSheetView.Columns(0).BackColor = Drawing.Color.Yellow
FpSpread1.ActiveSheetView.Columns(0).CellType = New TextCellType With {.AllowWrap = True}
Dim intCell As New IntegerCellType
intCell.MinimumValue = 1
intCell.MaximumValue = 999
GcCharacterTypeValidator1.ID = "dataTypeValidator1"
GcCharacterTypeValidator1.ValidateOnInput = True
GcCharacterTypeValidator1.CharacterSet = "9"
GcCharacterTypeValidator1.ValidatorActionID = "GcValidatorAction1"
Dim valProc As New ValueProcess
valProc.ValueProcessOption = ValueProcessOption.Restore
GcValidatorAction1.DefaultActions.Add(valProc)
intCell.Validators.Add(GcCharacterTypeValidator1)
FpSpread1.ActiveSheetView.Columns(1).CellType = intCell
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<FarPoint:FpSpread ID="FpSpread1" runat="server" BorderColor="#A0A0A0" BorderStyle="Solid" BorderWidth="1px" Height="200" Width="400">
<CommandBar BackColor="#F6F6F6" ButtonFaceColor="Control" ButtonHighlightColor="ControlLightLight" ButtonShadowColor="ControlDark">
</CommandBar>
<Sheets>
<FarPoint:SheetView SheetName="Sheet1">
</FarPoint:SheetView>
</Sheets>
</FarPoint:FpSpread>
<im_validator:GcCharacterTypeValidator ID="GcCharacterTypeValidator1" runat="server" ErrorMessage="GcCharacterTypeValidator" HasLoadFromXml="True"></im_validator:GcCharacterTypeValidator>
<im_extenders:GcValidatorAction ID="GcValidatorAction1" runat="server"></im_extenders:GcValidatorAction>
</form>
</body>
</html>
下面是全的文件:
<%@ Page Language="VB" Inherits="System.Web.UI.Page" %>
<%@ Register assembly="GrapeCity.Web.Input.v100, Version=10.0.4000.2012, Culture=neutral, PublicKeyToken=c3bd7c1dccef5128" namespace="GrapeCity.Web.Input.IMValidators" tagprefix="im_validator" %>
<%@ Register assembly="GrapeCity.Web.Input.v100, Version=10.0.4000.2012, Culture=neutral, PublicKeyToken=c3bd7c1dccef5128" namespace="GrapeCity.Web.Input.IMExtenders" tagprefix="im_extenders" %>
<!DOCTYPE html>
<script language="VB" type="text/VB" runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
InitVaSpread1()
End Sub
Private Sub InitVaSpread1()
FpSpread1.EditModeReplace = True
FpSpread1.ProcessTab = True
FpSpread1.HorizontalScrollBarPolicy = ScrollBarPolicy.Never
FpSpread1.VerticalScrollBarPolicy = ScrollBarPolicy.Always
FpSpread1.ActiveSheetView.DefaultRowHeight = 37
FpSpread1.ActiveSheetView.RowCount = 4
FpSpread1.ActiveSheetView.ColumnCount = 2
FpSpread1.ColumnHeader.Cells(0, 0).Value = "Col1"
FpSpread1.ColumnHeader.Cells(0, 1).Value = "Col2"
FpSpread1.ActiveSheetView.Columns(0).Width = 100
FpSpread1.ActiveSheetView.Columns(1).Width = 100
FpSpread1.ActiveSheetView.Columns(0).BackColor = Drawing.Color.Yellow
FpSpread1.ActiveSheetView.Columns(0).CellType = New TextCellType With {.AllowWrap = True}
Dim intCell As New IntegerCellType
intCell.MinimumValue = 1
intCell.MaximumValue = 999
GcCharacterTypeValidator1.ID = "dataTypeValidator1"
GcCharacterTypeValidator1.ValidateOnInput = True
GcCharacterTypeValidator1.CharacterSet = "9"
GcCharacterTypeValidator1.ValidatorActionID = "GcValidatorAction1"
Dim valProc As New ValueProcess
valProc.ValueProcessOption = ValueProcessOption.Restore
GcValidatorAction1.DefaultActions.Add(valProc)
intCell.Validators.Add(GcCharacterTypeValidator1)
FpSpread1.ActiveSheetView.Columns(1).CellType = intCell
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<FarPoint:FpSpread ID="FpSpread1" runat="server" BorderColor="#A0A0A0" BorderStyle="Solid" BorderWidth="1px" Height="200" Width="400">
<CommandBar BackColor="#F6F6F6" ButtonFaceColor="Control" ButtonHighlightColor="ControlLightLight" ButtonShadowColor="ControlDark">
</CommandBar>
<Sheets>
<FarPoint:SheetView SheetName="Sheet1">
</FarPoint:SheetView>
</Sheets>
</FarPoint:FpSpread>
<im_validator:GcCharacterTypeValidator ID="GcCharacterTypeValidator1" runat="server" ErrorMessage="GcCharacterTypeValidator" HasLoadFromXml="True"></im_validator:GcCharacterTypeValidator>
<im_extenders:GcValidatorAction ID="GcValidatorAction1" runat="server"></im_extenders:GcValidatorAction>
</form>
</body>
</html>
我试着重现问题 测试了,使用validator后原有验证就失效了,需要您在Validator里实现所有验证 谢谢您的回答。
InputMan只提供了下面六种验证控件,没有提供最大最小值的验证。
GcCharacterTypeValidator,GcDataTypeValidator,GcDateDifferenceValidator,
GcDateRangeValidator,GcForbiddenTextValidator,GcTextLengthValidator
需要实现自定义验证控件才能实现吗?
如何实现自定义验证控件能提供些帮助吗?
麻烦再帮忙看看,万分感激。
也可以看看微软本身提供的一些Validator。 结合一起使用 日期时间型单元格(DateTimeCellType)也有同样的问题。绑定了InputMan的检证控件GcCharacterTypeValidator之后,
时间最大值最小值Check也会失效。还有没有别的解决方案。 这个没有了,这个和之前一样,结合使用。
页:
[1]