書式による入力制限 - 数値コントロール -

数値コントロールには入力時と表示時のそれぞれの書式を設定できます。接頭語および接尾語は、正数と負数で別々に指定可能です。

入力確認
■入力書式
書式 通貨記号
接頭書式[正数] 接尾書式[正数]
接頭書式[負数] 接尾書式[負数]
■表示書式
書式 通貨記号
接頭書式[正数] 接尾書式[正数]
接頭書式[負数] 接尾書式[負数]

ソースコード

別ウィンドウで表示
using System;

public partial class Format_GcNumber : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
             GcComboBox1.SelectedIndex = 0;
             GcComboBox2.SelectedIndex = 0;
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        // 入力書式を設定します
        GcNumber1.Format.Digit = GcComboBox1.Text;
        GcNumber1.Format.PositivePrefix = PrefixPositive.Text;
        GcNumber1.Format.NegativePrefix = PrefixNegative.Text;
        GcNumber1.Format.PositiveSuffix = SuffixPositive.Text;
        GcNumber1.Format.NegativeSuffix = SuffixNegative.Text;
        GcNumber1.CurrencySymbol = Currency.Text;

        // 表示書式を設定します
        GcNumber1.DisplayFormat.Digit = GcComboBox2.Text;
        GcNumber1.DisplayFormat.PositivePrefix = DisplayPrefixPositive.Text;
        GcNumber1.DisplayFormat.NegativePrefix = DisplayPrefixNegative.Text;
        GcNumber1.DisplayFormat.PositiveSuffix = DisplaySuffixPositive.Text;
        GcNumber1.DisplayFormat.NegativeSuffix = DisplaySuffixNegative.Text;
    }
}

Partial Class Format_GcNumber
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            GcComboBox1.SelectedIndex = 0
            GcComboBox2.SelectedIndex = 0
        End If
    End Sub

    Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
        ' 入力書式を設定します
        GcNumber1.Format.Digit = GcComboBox1.Text
        GcNumber1.Format.PositivePrefix = PrefixPositive.Text
        GcNumber1.Format.NegativePrefix = PrefixNegative.Text
        GcNumber1.Format.PositiveSuffix = SuffixPositive.Text
        GcNumber1.Format.NegativeSuffix = SuffixNegative.Text
        GcNumber1.CurrencySymbol = Currency.Text

        ' 表示書式を設定します
        GcNumber1.DisplayFormat.Digit = GcComboBox2.Text
        GcNumber1.DisplayFormat.PositivePrefix = DisplayPrefixPositive.Text
        GcNumber1.DisplayFormat.NegativePrefix = DisplayPrefixNegative.Text
        GcNumber1.DisplayFormat.PositiveSuffix = DisplaySuffixPositive.Text
        GcNumber1.DisplayFormat.NegativeSuffix = DisplaySuffixNegative.Text
    End Sub

End Class

<%@ page title="" language="C#" masterpagefile="~/MasterPage.master" autoeventwireup="true" inherits="Format_GcNumber, App_Web_er03pujf" stylesheettheme="SkinFile" %>

<%@ Register assembly="GrapeCity.Web.Input.v80, Version=8.0.2016.1130, Culture=neutral, PublicKeyToken=c3bd7c1dccef5128" namespace="GrapeCity.Web.Input.IMNumber" tagprefix="im_number" %>
<%@ Register assembly="GrapeCity.Web.Input.v80, Version=8.0.2016.1130, Culture=neutral, PublicKeyToken=c3bd7c1dccef5128" namespace="GrapeCity.Web.Input.IMCombo" tagprefix="im_combo" %>
<%@ Register assembly="GrapeCity.Web.Input.v80, Version=8.0.2016.1130, Culture=neutral, PublicKeyToken=c3bd7c1dccef5128" namespace="GrapeCity.Web.Input.IMEdit" tagprefix="im_edit" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <script type="text/javascript">

        // 入力書式
        // 書式を設定します。
        function GcComboBox1_TextChanged(sender, eArgs) {
            if (!document.getElementById("isClient").checked) return;
            FindIMControl("<%=GcNumber1.ClientID %>").SetFormatDigit(sender.GetText());
        }
        // 接頭書式(正数)を設定します。
        function PrefixPositive_TextChanged(sender, eArgs) {
            if (!document.getElementById("isClient").checked) return;
            FindIMControl("<%=GcNumber1.ClientID %>").SetPositivePrefix(sender.GetText());
        }
        // 接頭書式(負数)を設定します。
        function PrefixNegative_TextChanged(sender, eArgs) {
            if (!document.getElementById("isClient").checked) return;
            FindIMControl("<%=GcNumber1.ClientID %>").SetNegativePrefix(sender.GetText());
		}
        // 接尾書式(正数)を設定します。
        function SuffixPositive_TextChanged(sender, eArgs) {
            if (!document.getElementById("isClient").checked) return;
		    FindIMControl("<%=GcNumber1.ClientID %>").SetPositiveSuffix(sender.GetText());
		}
        // 接尾書式(負数)を設定します。
        function SuffixNegative_TextChanged(sender, eArgs) {
            if (!document.getElementById("isClient").checked) return;
		    FindIMControl("<%=GcNumber1.ClientID %>").SetNegativeSuffix(sender.GetText());
		}
        // 通貨記号を設定します。
        function Currency_TextChanged(sender, eArgs) {
            if (!document.getElementById("isClient").checked) return;
            FindIMControl("<%=GcNumber1.ClientID %>").SetCurrencySymbol(sender.GetText());
        }

        // 表示書式
        // 書式を設定します。
        function GcComboBox2_TextChanged(sender, eArgs) {
            if (!document.getElementById("isClient").checked) return;
            FindIMControl("<%=GcNumber1.ClientID %>").SetDisplayFormatDigit(sender.GetText());
        }
        // 接頭書式(正数)を設定します。
        function DisplayPrefixPositive_TextChanged(sender, eArgs) {
            if (!document.getElementById("isClient").checked) return;
            FindIMControl("<%=GcNumber1.ClientID %>").SetDisplayPositivePrefix(sender.GetText());
        }
        // 接頭書式(負数)を設定します。
        function DisplayPrefixNegative_TextChanged(sender, eArgs) {
            if (!document.getElementById("isClient").checked) return;
            FindIMControl("<%=GcNumber1.ClientID %>").SetDisplayNegativePrefix(sender.GetText());
        }
        // 接尾書式(正数)を設定します。
        function DisplaySuffixPositive_TextChanged(sender, eArgs) {
            if (!document.getElementById("isClient").checked) return;
            FindIMControl("<%=GcNumber1.ClientID %>").SetDisplayPositiveSuffix(sender.GetText());
        }
        // 接尾書式(負数)を設定します。
        function DisplaySuffixNegative_TextChanged(sender, eArgs) {
            if (!document.getElementById("isClient").checked) return;
            FindIMControl("<%=GcNumber1.ClientID %>").SetDisplayNegativeSuffix(sender.GetText());
        }

    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <div class="sample">
        <table>
            <tr>
                <th>入力確認</th>
            </tr>
            <tr>
                <td>
                    <im_number:GcNumber ID="GcNumber1" runat="server" HasLoadFromXml="True" 
                        Width="300px">
                        <Format Digit="####0.##" NegativePrefix="-$" PositivePrefix="$" />
                        <DisplayFormat Digit="####0.##" NegativePrefix="税込 ▲" NegativeSuffix="円" 
                            PositivePrefix="税込 " PositiveSuffix="円" />
                        <helpvalue value="10000" ></helpvalue>
                    </im_number:GcNumber>
                </td>
            </tr>
        </table>
    </div>
    <label style="font-size:80%;"><input type="checkbox" id="isClient" checked="checked" /> クライアント側の設定を有効にする</label>
    <table class="inputTable">
        <tr>
            <td colspan="4" class="inputTd">■入力書式</td>
        </tr>
        <tr>
            <th class="inputTh">書式</th>
            <td class="inputTd">
                <im_combo:GcComboBox ID="GcComboBox1" runat="server" HasLoadFromXml="True">
                    <clientevents textchanged="GcComboBox1_TextChanged"></clientevents>
                    <comboitem></comboitem>
                    <subitem index="0" value="#####"></subitem>
                    <comboitem></comboitem>
                    <subitem index="1" value="00000"></subitem>
                    <comboitem></comboitem>
                    <subitem index="2" value="##,###"></subitem>
                    <comboitem></comboitem>
                    <subitem index="3" value="##,##0"></subitem>
                    <comboitem></comboitem>
                    <subitem index="4" value="##,##0.##"></subitem>
                    <comboitem></comboitem>
                    <subitem index="5" value="##,##0.00"></subitem>
                    <helpvalue ></helpvalue>
                </im_combo:GcComboBox>
            </td>
            <th class="inputTh">通貨記号</th>
            <td class="inputTd">
                <im_edit:GcTextBox ID="Currency" runat="server" HasLoadFromXml="True" Text="\">
                    <clientevents textchanged="Currency_TextChanged"></clientevents>
                </im_edit:GcTextBox>
            </td>
        </tr>
        <tr>
            <th class="inputTh">接頭書式[正数]</th>
            <td class="inputTd">
                <im_edit:GcTextBox ID="PrefixPositive" runat="server" HasLoadFromXml="True" Text="$">
                    <clientevents textchanged="PrefixPositive_TextChanged"></clientevents>
                </im_edit:GcTextBox>
            </td>
            <th class="inputTh">接尾書式[正数]</th>
            <td class="inputTd">
                <im_edit:GcTextBox ID="SuffixPositive" runat="server" HasLoadFromXml="True">
                    <clientevents textchanged="SuffixPositive_TextChanged"></clientevents>
                </im_edit:GcTextBox>
            </td>
        </tr>
        <tr>
            <th class="inputTh">接頭書式[負数]</th>
            <td class="inputTd">
                <im_edit:GcTextBox ID="PrefixNegative" runat="server" HasLoadFromXml="True" Text="-$">
                    <clientevents textchanged="PrefixNegative_TextChanged"></clientevents>
                </im_edit:GcTextBox>
            </td>
            <th class="inputTh">接尾書式[負数]</th>
            <td class="inputTd">
                <im_edit:GcTextBox ID="SuffixNegative" runat="server" HasLoadFromXml="True">
                    <clientevents textchanged="SuffixNegative_TextChanged"></clientevents>
                </im_edit:GcTextBox>
            </td>
        </tr>
        </table>
    <table class="inputTable">
        <tr>
            <td colspan="4" class="inputTd">■表示書式</td>
        </tr>
        <tr>
            <th class="inputTh">書式</th>
            <td class="inputTd">
                <im_combo:GcComboBox ID="GcComboBox2" runat="server" HasLoadFromXml="True">
                    <clientevents textchanged="GcComboBox2_TextChanged"></clientevents>
                    <comboitem></comboitem>
                    <subitem index="0" value="#####"></subitem>
                    <comboitem></comboitem>
                    <subitem index="1" value="00000"></subitem>
                    <comboitem></comboitem>
                    <subitem index="2" value="##,###"></subitem>
                    <comboitem></comboitem>
                    <subitem index="3" value="##,##0"></subitem>
                    <comboitem></comboitem>
                    <subitem index="4" value="##,##0.##"></subitem>
                    <comboitem></comboitem>
                    <subitem index="5" value="##,##0.00"></subitem>
                    <comboitem></comboitem>
                    <subitem index="6" value="[DBNum1]G"></subitem>
                    <comboitem></comboitem>
                    <subitem index="7" value="[DBNum2]G"></subitem>
                    <comboitem></comboitem>
                    <subitem index="8" value="[DBNum3]G"></subitem>
                    <comboitem></comboitem>
                    <subitem index="9" value="[DBNum4]G"></subitem>
                    <comboitem></comboitem>
                    <subitem index="10" value="[###:千]"></subitem>
                    <comboitem></comboitem>
                    <subitem index="11" value="[####:万]"></subitem>
                    <helpvalue ></helpvalue>
                </im_combo:GcComboBox>
            </td>
            <th class="inputTh">通貨記号</th>
            <td class="inputTd">
                <im_edit:GcTextBox ID="GcTextBox6" runat="server" HasLoadFromXml="True" 
                    Text="\(入力書式と同様)" CssStyle=".aspNetDisabled{}" Enabled="False">
                </im_edit:GcTextBox>
            </td>
        </tr>
        <tr>
            <th class="inputTh">接頭書式[正数]</th>
            <td class="inputTd">
                <im_edit:GcTextBox ID="DisplayPrefixPositive" runat="server" HasLoadFromXml="True" Text="税込 ">
                    <clientevents textchanged="DisplayPrefixPositive_TextChanged"></clientevents>
                </im_edit:GcTextBox>
            </td>
            <th class="inputTh">接尾書式[正数]</th>
            <td class="inputTd">
                <im_edit:GcTextBox ID="DisplaySuffixPositive" runat="server" HasLoadFromXml="True" Text="円">
                    <clientevents textchanged="DisplaySuffixPositive_TextChanged"></clientevents>
                </im_edit:GcTextBox>
            </td>
        </tr>
        <tr>
            <th class="inputTh">接頭書式[負数]</th>
            <td class="inputTd">
                <im_edit:GcTextBox ID="DisplayPrefixNegative" runat="server" HasLoadFromXml="True" Text="税込 ▲">
                    <clientevents textchanged="DisplayPrefixNegative_TextChanged"></clientevents>
                </im_edit:GcTextBox>
            </td>
            <th class="inputTh">接尾書式[負数]</th>
            <td class="inputTd">
                <im_edit:GcTextBox ID="DisplaySuffixNegative" runat="server" HasLoadFromXml="True" Text="円">
                    <clientevents textchanged="DisplaySuffixNegative_TextChanged"></clientevents>
                </im_edit:GcTextBox>
            </td>
        </tr>
    </table>
    <center>
        <asp:Button ID="Button1" runat="server" Text="サーバー側で設定" 
             onclick="Button1_Click" CssClass="button_nowidth" />
    </center>
</asp:Content>


このページの先頭へ戻る