.NET ----- 将文本框改成下划线,将下拉框改为下拉下划线

1、实现:前端直接进行控制,只能输入数字,

原先:

 

 修改:

在页面初始化的时候加上 , SetTextBoxInput()

            base.SetTextBoxInput(tbFee_KaoZhengFei, 121);
            base.SetTextBoxInput(tbFee_QiTa, 121);
            base.SetTextBoxInput(tbFee_XueFei_back, 121);
            base.SetTextBoxInput(tbFee_ZhuSuFei, 121);

变成如下:只能输入数字形式

 2、只改变样式,不控制输入方式

如:

 

 在初始化时改变 texbox 和 DropDownList 的样式

 

 借助  SetDropDownListStyleLineBlack() 和  SetTextBoxStyleLineBlack

            base.SetDropDownListStyleLineBlack(this.ddlsqlAreaSheng_GongSi_4001_Code, 100);
            base.SetDropDownListStyleLineBlack(this.ddlsqlAreaShi_GongSi_4001_Code, 100);
            base.SetDropDownListStyleLineBlack(this.ddlsqlAreaXian_GongSi_4001_Code, 100);
            base.SetTextBoxStyleLineBlack(tbsqlGangWei_Name, 100);
            base.SetTextBoxStyleLineBlack(tbsqlGongSi_Name, 100);

 

3、具体实现方法

  #region 数字文本框限制输入
    /// <summary>
    /// 数字文本框的样式
    /// </summary>
    /// <param name="tb"></param>
    public void SetTextBoxInput(TextBox tb)
    {
        SetTextBoxInput(tb, -1);
    }

    public void SetTextBoxInput(TextBox tb, int iWidth)
    {
        SetTextBoxInput(tb, iWidth, 14, true, true);
    }

    public void SetTextBoxInput_LabelBig(TextBox tb, int iWidth, Label LabelDaXie)
    {
        SetTextBoxInput_LabelBig(tb, iWidth, LabelDaXie, null);
    }

    public void SetTextBoxInput_LabelBig(TextBox tb, int iWidth, Label LabelDaXie, Literal LiteralJs)
    {
        string sid = tb.ID;
        SetTextBoxOnkeyup(tb, iWidth);
        string script = "<script src=\"../../qdcnt_js/Arabia_to_Chinese.js\" type=\"text/javascript\"></script><script type=\"text/javascript\">function jisuan_" + sid + "(){var dcount=0;";
        script += "if(document .getElementById (\"" + tb.ClientID + "\").value!=\"\"){";
        script += "dcount=parseFloat(document .getElementById (\"" + tb.ClientID + "\").value);";
        script += "document .getElementById (\"" + LabelDaXie.ClientID + "\").innerHTML=Arabia_to_Chinese(dcount.toFixed(2));}else{document .getElementById (\"" + LabelDaXie.ClientID + "\").innerHTML=\"\"}}</script>";
        if (LiteralJs != null)
            LiteralJs.Text = script;
        tb.Attributes.Add("onkeyup", "jisuan_" + sid + "()");
    }

    /// <summary>
    /// 数字文本框的样式
    /// </summary>
    /// <param name="tb"></param>
    /// <param name="iWidth"></param>
    public void SetTextBoxInput(TextBox tb, int iWidth, int iFontSize, bool isBold, bool isRed)
    {
        tb.Attributes.Add("onKeyPress", "if((event.keyCode<48 || event.keyCode>57) && event.keyCode!=46)event.returnValue=false");

        string slabel = string.Empty;

        tb.Attributes.Add("onkeyup", "if(isNaN(value))execCommand('undo');");

        StringBuilder sb = new StringBuilder();

        sb.Append("border-bottom-width: 1px;");
        sb.Append("border-bottom-style: solid;");
        sb.Append("border-bottom-color: #D4D0C8;");
        sb.Append("text-align: center;");
        sb.Append("font-size: " + iFontSize + "px;");
        if (isBold)
            sb.Append("font-weight: bold;");
        if (isRed)
            sb.Append("color: #FF0000;");
        sb.Append("border-top-width: 0px;");
        sb.Append("border-right-width: 0px;");
        sb.Append("border-left-width: 0px;");
        sb.Append("border-top-style: none;");
        sb.Append("border-right-style: none;");
        sb.Append("border-left-style: none;");
        if (iWidth > 0)
            sb.Append("width:" + iWidth + "px;");

        tb.Attributes.Add("style", sb.ToString());

    }

    public void SetTextBoxInput(TextBox tb, int iWidth, int iFontSize, bool isBold, string sForeColor)
    {
        sForeColor = sForeColor.Replace("#", "");
        tb.Attributes.Add("onKeyPress", "if((event.keyCode<48 || event.keyCode>57) && event.keyCode!=46)event.returnValue=false");

        string slabel = string.Empty;

        tb.Attributes.Add("onkeyup", "if(isNaN(value))execCommand('undo');");

        StringBuilder sb = new StringBuilder();

        sb.Append("border-bottom-width: 1px;");
        sb.Append("border-bottom-style: solid;");
        sb.Append("border-bottom-color: #D4D0C8;");
        sb.Append("text-align: center;");
        sb.Append("font-size: " + iFontSize + "px;");
        if (isBold)
            sb.Append("font-weight: bold;");
        if (sForeColor != string.Empty)
            sb.Append("color: #" + sForeColor + ";");
        sb.Append("border-top-width: 0px;");
        sb.Append("border-right-width: 0px;");
        sb.Append("border-left-width: 0px;");
        sb.Append("border-top-style: none;");
        sb.Append("border-right-style: none;");
        sb.Append("border-left-style: none;");
        if (iWidth > 0)
            sb.Append("width:" + iWidth + "px;");

        tb.Attributes.Add("style", sb.ToString());

    }

    /// <summary>
    /// 数字文本框的样式
    /// </summary>
    /// <param name="tb"></param>
    public void SetTextBoxOnkeyup(TextBox tb)
    {
        SetTextBoxOnkeyup(tb, -1);
    }

    public void SetTextBoxOnkeyup(TextBox tb, int iWidth)
    {
        SetTextBoxOnkeyup(tb, iWidth, 14, true);
    }

    public void SetTextBoxOnkeyup(TextBox tb, int iWidth, int ifontsize, bool isbold)
    {
        SetTextBoxOnkeyup(tb, iWidth, 14, true, true);
    }
    /// <summary>
    /// 数字文本框的样式
    /// </summary>
    /// <param name="tb"></param>
    /// <param name="iWidth"></param>
    public void SetTextBoxOnkeyup(TextBox tb, int iWidth, int ifontsize, bool isbold, bool isRed)
    {
        tb.Attributes.Add("onKeyPress", "if((event.keyCode<48 || event.keyCode>57) && event.keyCode!=46)event.returnValue=false");

        string slabel = string.Empty;

        StringBuilder sb = new StringBuilder();

        sb.Append("border-bottom-width: 1px;");
        sb.Append("border-bottom-style: solid;");
        sb.Append("border-bottom-color: #D4D0C8;");
        sb.Append("text-align: center;");
        sb.Append("font-size: " + ifontsize + "px;");
        if (isbold)
            sb.Append("font-weight: bold;");
        if (isRed)
            sb.Append("color: #FF0000;");

        sb.Append("border-top-width: 0px;");
        sb.Append("border-right-width: 0px;");
        sb.Append("border-left-width: 0px;");
        sb.Append("border-top-style: none;");
        sb.Append("border-right-style: none;");
        sb.Append("border-left-style: none;");
        if (iWidth > 0)
            sb.Append("width:" + iWidth + "px;");

        tb.Attributes.Add("style", sb.ToString());

    }

    public void SetTextBoxOnkeyup(TextBox tb, int iWidth, int ifontsize, bool isbold, string sForeColor)
    {
        sForeColor = sForeColor.Replace("#", "");
        tb.Attributes.Add("onKeyPress", "if((event.keyCode<48 || event.keyCode>57) && event.keyCode!=46)event.returnValue=false");

        string slabel = string.Empty;

        StringBuilder sb = new StringBuilder();

        sb.Append("border-bottom-width: 1px;");
        sb.Append("border-bottom-style: solid;");
        sb.Append("border-bottom-color: #D4D0C8;");
        sb.Append("text-align: center;");
        sb.Append("font-size: " + ifontsize + "px;");
        if (isbold)
            sb.Append("font-weight: bold;");
        if (sForeColor != string.Empty)
            sb.Append("color: #" + sForeColor + ";");

        sb.Append("border-top-width: 0px;");
        sb.Append("border-right-width: 0px;");
        sb.Append("border-left-width: 0px;");
        sb.Append("border-top-style: none;");
        sb.Append("border-right-style: none;");
        sb.Append("border-left-style: none;");
        if (iWidth > 0)
            sb.Append("width:" + iWidth + "px;");

        tb.Attributes.Add("style", sb.ToString());

    }

    #endregion

 

 

posted on 2020-08-14 16:58  obge  阅读(345)  评论(0编辑  收藏  举报