this is my list view
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<asp:ListView ID="ListView1" runat="server" DataKeyNames="Year"
DataSourceID="AccountValueFundsDataSource" InsertItemPosition="LastItem">
........
</asp:ListView>
This is my data source
<asp:SqlDataSource ID="AccountValueFundsDataSource" runat="server"
ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:Life_InsuranceConnectionString %>"
DeleteCommand="DELETE FROM [AccountValueFunds] WHERE [Year] = @original_Year AND [avfcharge] = @original_avfcharge"
InsertCommand="INSERT INTO [AccountValueFunds] ([Year], [avfcharge]) VALUES (@Year, @avfcharge)"
OldValuesParameterFormatString="original_{0}"
SelectCommand="SELECT * FROM [AccountValueFunds]"
UpdateCommand="UPDATE [AccountValueFunds] SET [avfcharge] = @avfcharge WHERE [Year] = @original_Year AND [avfcharge] = @original_avfcharge">
<DeleteParameters>
<asp:Parameter Name="original_Year" Type="Int32" />
<asp:Parameter Name="original_avfcharge" Type="Decimal" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Year" Type="Int32" />
<asp:Parameter Name="avfcharge" Type="Decimal" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="avfcharge" Type="Decimal" />
<asp:Parameter Name="original_Year" Type="Int32" />
<asp:Parameter Name="original_avfcharge" Type="Decimal" />
</UpdateParameters>
</asp:SqlDataSource>
my question is how to validate input? example if a users enters a string where the type of parameter is decimal or integer??
You can handle that validation with RegularExpressionValidator – MSDN Article, RegularExpressionValidator – W3School.
You need the
ValidationExpressionto allowdecimals andintegers but not allowstrings.Check these
Accept only (0-9) integer and one decimal point(decimal point is also optional).
Input for Numeric values. Handles negatives, and comma formatted values. Also handles a single decimal point
Regular Expression Validator – Numbers only no letters no spaces