Hie,
I create a dynamique HtmlTable, in each cell of this HtmlTable put a new control ( dropdownlist,la bel,..) and then want to create handler so that if i change the select item in the dop downlist i change the text displayed in the label in the same row.
hier is my code:
using System;
using System.Collecti ons;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Sess ionState;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;
using System.Data.Sql Client;
namespace gestion_commerc iale
{
/// <summary>
/// Description résumée de [!output SAFE_CLASS_NAME].
/// </summary>
public class bon : System.Web.UI.P age
{
protected System.Web.UI.W ebControls.Labe l xnumbon;
protected System.Web.UI.W ebControls.Labe l xcompte;
protected System.Web.UI.W ebControls.Labe l xdate;
protected System.Web.UI.W ebControls.Labe l xcode;
protected System.Web.UI.W ebControls.Drop DownList xclient;
protected System.Web.UI.W ebControls.Text Box xnbre;
protected System.Web.UI.H tmlControls.Htm lTable Table1;
private void Page_Load(objec t sender, System.EventArg s e)
{
if (!IsPostBack )
{
string sql_cl= "SELECT nom_client FROM client order by nom_client asc";
NumBon numero_bon = new NumBon();
xnumbon.Text = numero_bon.getN umBon().ToStrin g();
xcompte.Text= Session["compte"].ToString();
DataBase db= new DataBase();
db.setDbConnect ion();
db.getDbConnect ion().Open();
RecordSet rs = new RecordSet(sql_c l,db.getDbConne ction());
xclient.DataSou rce = rs.execSelect() ;
xclient.DataTex tField = "nom_client ";
xclient.DataBin d();
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArg s e)
{
//
// CODEGENÂ*: Cet appel est requis par le Concepteur Web Form ASP.NET.
//
InitializeCompo nent();
base.OnInit(e);
}
/// <summary>
/// Méthode requise pour la prise en charge du concepteur - ne modifiez pas
/// le contenu de cette méthode avec l'éditeur de code.
/// </summary>
private void InitializeCompo nent()
{
this.xnbre.Text Changed += new System.EventHan dler(this.xnbre _TextChanged);
this.Load += new System.EventHan dler(this.Page_ Load);
}
#endregion
private void xnbre_TextChang ed(object sender, System.EventArg s e)
{
int numrows = Convert.ToInt32 (xnbre.Text);
// boucle selon le nombre de produit
// get the number of rows and cells to build
// loop through the given number of rows
for ( int r = 0; r < numrows; r++ )
{
// instantiate a new row
HtmlTableRow row = new HtmlTableRow ( );
// set bgcolor for alternating rows
if ( r % 2 == 1 ) row.BgColor = "beige";
// loop through the given number of cells
for ( int c = 0; c < 8; c++ )
{
// instantiate a new cell
HtmlTableCell cell = new HtmlTableCell ( );
// add cell content
if(c==4)
{
DropDownList stationDifusion = new DropDownList();
stationDifusion .ID="st"+r+"";
//stationDifusion .SelectedIndexC hanged += new System.EventHan dler(this.stati onDifusion_Sele ctedIndexChange d);//
stationDifusion .Width=100;
//creation d'un array liste
ArrayList station=new ArrayList( );
station.Add("Tà ©lévision");
station.Add("Ra dio RSI");
station.Add("Ch aîne Nationale");
station.Add("Da kar FM" );
station.Add("St Louis FM");
station.Add("Lo uga FM");
station.Add("Th ies FM");
station.Add("Ka olack FM");
station.Add("Di ourbel FM");
station.Add("Ko lda FM");
station.Add("Zi guinchor FM");
station.Add("Ta mba FM");
station.Add("Fa tick FM");
station.Add("Sy nchronisation") ;
stationDifusion .DataSource=sta tion;// fin array liste
stationDifusion .DataBind();
cell.Controls.A dd (stationDifusio n);
}
else if (c==2)
{
DropDownList ddl = new DropDownList();
ddl.ID="hd"+r+" ";
ddl.Width=100;
//creation d'un array liste
ArrayList heuredifusion=n ew ArrayList ( );
heuredifusion.A dd ( "12h:30" );
heuredifusion.A dd ( "13h:00" );
heuredifusion.A dd ( "14h:00" );
heuredifusion.A dd ( "14h:15" );
heuredifusion.A dd ( "15h:00" );
heuredifusion.A dd ( "17h:00" );
heuredifusion.A dd ( "19h:30" );
heuredifusion.A dd ( "20h:00" );
heuredifusion.A dd ( "20h:30" );
heuredifusion.A dd ( "21h:00" );
heuredifusion.A dd ( "23h:30" );
heuredifusion.A dd ( "23h:45" );
ddl.DataSource= heuredifusion;// fn array liste
ddl.DataBind();
cell.Controls.A dd (ddl);
}
else if (c==6)
{
DropDownList ddl = new DropDownList();
DropDownList ddlHeureDifusio n = new DropDownList();
ddlHeureDifusio n.ID="maj"+r+"" ;
ddlHeureDifusio n.Width=100;
//creation d'un array liste
ArrayList majoration=new ArrayList ( );
majoration.Add ( "0" );
majoration.Add ( "5" );
majoration.Add ( "10" );
majoration.Add ( "15" );
majoration.Add ( "20" );
majoration.Add ( "25" );
majoration.Add ( "30" );
majoration.Add ( "35" );
majoration.Add ("40" );
majoration.Add ( "45" );
majoration.Add ( "50" );
majoration.Add ( "55" );
majoration.Add ( "60" );
majoration.Add ( "65" );
majoration.Add ( "70" );
majoration.Add ( "75" );
majoration.Add ( "80" );
majoration.Add ( "85" );
majoration.Add ( "90" );
majoration.Add ( "95" );
majoration.Add ( "100" );
ddl.DataSource = majoration;// fin array liste
ddl.DataBind();
cell.Controls.A dd (ddl);
}
else if(c==0)
{
string sql_query="sele ct nom_prod,pu from produit order by nom_prod asc";
//cell.Controls.A dd ( new HtmlInputText() );
DropDownList ddlDesi = new DropDownList();
DropDownList ddlPU = new DropDownList();
//*************** *************** *************** ******
DataBase db= new DataBase();
db.setDbConnect ion();
db.getDbConnect ion().Open();
RecordSet rs = new RecordSet(sql_q uery,db.getDbCo nnection());
ddlDesi.DataSou rce = rs.execSelect() ;
ddlDesi.DataTex tField = "nom_prod";
ddlDesi.DataBin d();
cell.Controls.A dd (ddlDesi);
}
else if(c==1)
{
HtmlInputText itnom=new HtmlInputText() ;
itnom.Size=10;
cell.Controls.A dd(itnom);
}
else if(c==3)
{
HtmlInputText itqte=new HtmlInputText() ;
itqte.Size=2;
cell.Controls.A dd(itqte);
}
// add the cell to the Cells collection
row.Cells.Add ( cell );
}
// add the row to the Rows collection
Table1.Rows.Add (row);
}
}
}
}
---
Posted using Wimdows.net NntpNews Component -
Post Made from http://www.DotNetJunkies.com/newsgroups Our newsgroup engine supports Post Alerts, Ratings, and Searching.