close

    protected void Page_Load(object sender, EventArgs e)
    {
        //動態建立10個文字框;
        for (int i = 1; i <= 10; i++)
        {
            TextBox tb = new TextBox();
            tb.ID = "textbox" + i;
            tb.Width = 100;
            tb.AutoPostBack = true;


            //動態為每個文字框加上變更內容事件
            tb.TextChanged += Tb_TextChanged;
            PlaceHolder1.Controls.Add(tb);
            if (i < 10)
            {
                Literal l = new Literal();
                l.Text = "<br/>";
                PlaceHolder1.Controls.Add(l);
            }

        }
    }

    private void Tb_TextChanged(object sender, EventArgs e)
    {
        TextBox a = (TextBox)sender; //取得作用中文字框
        TextBox b = new TextBox();
        string s = a.ID.ToString(); //取得作用中文字框id名稱
        s = s.Substring(7, s.Length - 7); //取得id名稱中的數字部分
        if (Convert.ToInt16(s) < 10)
        {
            //讓下一個文字框取得焦點
            b = (TextBox)PlaceHolder1.FindControl("textbox" + (Convert.ToInt32(s) + 1));
            b.Focus();

        }
        else
        {
            b = (TextBox)PlaceHolder1.FindControl("textbox" + 1);
            b.Focus();
        }
    }
 

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 ylw1125 的頭像
    ylw1125

    程式搜集分享精靈

    ylw1125 發表在 痞客邦 留言(0) 人氣()