1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace TONNAMESPACE
{
public partial class WebForm1 : System.Web.UI.Page
{
private static IList<TextBox> m_kIColTxBx = new List<TextBox>();
protected void Page_Load( object sender, EventArgs e )
{
AddTextBox( m_kIColTxBx );
}
protected void TextBox1_TextChanged( object sender, EventArgs e )
{
Debug.WriteLine( "TextBox1_TextChanged ######" );
this.RemoveTextBox( m_kIColTxBx );
try
{
int iNbtxtBx;
if ( Int32.TryParse( ( (TextBox)( sender ) ).Text, out iNbtxtBx ) )
{
m_kIColTxBx.Clear();
for ( int i = 0; i < iNbtxtBx; ++i )
{
TextBox kTxBx = new TextBox();
kTxBx.ID = "TextBox_" + i.ToString();
kTxBx.Text = "Heure n° " + i.ToString();
kTxBx.Height = 30;
kTxBx.Width = 500;
kTxBx.Visible = true;
kTxBx.Enabled = true;
kTxBx.AutoPostBack = true;
m_kIColTxBx.Add( kTxBx );
}
AddTextBox( m_kIColTxBx );
}
}
catch ( Exception exc )
{
Debug.WriteLine( "ERROR : " + exc );
}
}
protected void TextBoxPhrase_TextChanged( object sender, EventArgs e )
{
Debug.WriteLine( " ###### TextBoxPhrase_TextChanged" );
this.RemoveTextBox( m_kIColTxBx );
TextBox kTxBx = ( (TextBox)( sender ) );
int iStart = m_kIColTxBx.IndexOf( kTxBx );
for ( int i = iStart; i < m_kIColTxBx.Count; ++i )
{
m_kIColTxBx[i].Text = kTxBx.Text;
}
AddTextBox( m_kIColTxBx );
}
protected void AddTextBox( IList<TextBox> TextBoxList )
{
IEnumerator kEnumerator = TextBoxList.GetEnumerator();
TextBox kTxBx;
while ( kEnumerator.MoveNext() )
{
kTxBx = ( (TextBox)( kEnumerator.Current ) );
kTxBx.TextChanged += new EventHandler( this.TextBoxPhrase_TextChanged );
this.form1.Controls.Add( kTxBx );
}
}
protected void RemoveTextBox( IList<TextBox> TextBoxList )
{
IEnumerator kEnumerator = TextBoxList.GetEnumerator();
while ( kEnumerator.MoveNext() )
{
this.form1.Controls.Remove( ( (TextBox)( kEnumerator.Current ) ) );
}
}
}
} |
Partager