bonjour,
j'ai un probleme, en fait je génére un tableau dhtml dynamique et je le rempli de controle (dropdownlist label, inputext ...) cependant chaque fois que je clique sur un bouton valider et que je veuiller récupéré les element rempli par l'utilisateur je n'y arrive pas. On dirai qu'avant d'execter le code qui est dans le bouton la page enleve tout les controles et les lignes ajouter dynamiquement ainsi si je recherche les contrles par rapport à leur id oubien que je passe le tableau généré a une autre page et que je cherche les elements ajoutés je ne trouve rien il y'a et il genére une erreur:
System.NullReferenceException: La référence d'objet n'est pas définie à une instance d'un objet.
voici mon code:using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace gestion_commerciale
{
/// <summary>
/// Description résumée de [!output SAFE_CLASS_NAME].
/// </summary>
public class bon : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label xnumbon;
protected System.Web.UI.WebControls.Label xcompte;
protected System.Web.UI.WebControls.Label xdate;
protected System.Web.UI.WebControls.Label xcode;
public HtmlTable xtable
{
get
{
return Table1;
}
}
private void Page_Load(object sender, System.EventArgs e)
{
this.EnableViewState=true;
Table1.EnableViewState=true;
if (!IsPostBack )
{
Table1.EnableViewState=true;
string sql_cl= "SELECT nom_client FROM client order by nom_client asc";
NumBon numero_bon = new NumBon();
xnumbon.Text = numero_bon.getNumBon().ToString();
xcompte.Text= Session["compte"].ToString();
DataBase db= new DataBase();
db.setDbConnection();
db.getDbConnection().Open();
RecordSet rs = new RecordSet(sql_cl,db.getDbConnection());
xclient.DataSource = rs.execSelect();
xclient.DataTextField = "nom_client";
xclient.DataBind();
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN : Cet appel est requis par le Concepteur Web Form ASP.NET.
//
InitializeComponent();
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 InitializeComponent()
{
this.Button2.Click += new System.EventHandler(this.Button2_Click);
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
/*HtmlInputText ddl =(HtmlInputText)this.Table1.FindControl(0+"lc"+1);
TextBox1.Text=ddl.Value;*/
//TextBox1.Text=ddl.s
//TextBox1.Text=ddl.SelectedItem.Text;
//Session.Add("tableau",Table1);
Server.Transfer("temp.aspx");
}
private void Button2_Click(object sender, System.EventArgs e)
{
int numrows = Convert.ToInt32 (xnbre.Text);
// boucle selon le nombre de produit
for ( int r = 0; r < numrows; r++ )
{
// instantiate a new row
HtmlTableRow row = new HtmlTableRow ( );
row.EnableViewState=true;
// 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 ( );
cell.EnableViewState=true;
// add cell content
if(c==0)
{
string sql_query="select distinct(nom_prod) from produit order by nom_prod asc";
DropDownList ddlDesi = new DropDownList();
//ddlDesi.EnableViewState=false;
//ddlDesi.AutoPostBack=true;
ddlDesi.ID=r+"lc"+c;
//DropDownList ddlDesi = (DropDownList)this.FindControl("l0c0");
DataBase db= new DataBase();
db.setDbConnection();
db.getDbConnection().Open();
RecordSet rs = new RecordSet(sql_query,db.getDbConnection());
ddlDesi.DataSource = rs.execSelect();
ddlDesi.DataTextField = "nom_prod";
ddlDesi.DataBind();
cell.Controls.Add (ddlDesi);
}
else if(c==1)
{
HtmlInputText itnom=new HtmlInputText();
itnom.ID=r+"lc"+c;
itnom.Size=10;
cell.Controls.Add(itnom);
}
else if (c==2)
{
DropDownList ddl = new DropDownList();
ddl.ID=r+"lc"+c;
ddl.Width=100;
//creation d'un array liste
ArrayList heuredifusion=new ArrayList ( );
heuredifusion.Add ( "12h:30" );
heuredifusion.Add ( "13h:00" );
heuredifusion.Add ( "14h:00" );
heuredifusion.Add ( "14h:15" );
heuredifusion.Add ( "15h:00" );
heuredifusion.Add ( "17h:00" );
heuredifusion.Add ( "19h:30" );
heuredifusion.Add ( "20h:00" );
heuredifusion.Add ( "20h:30" );
heuredifusion.Add ( "21h:00" );
heuredifusion.Add ( "23h:30" );
heuredifusion.Add ( "23h:45" );
ddl.DataSource=heuredifusion;// fn array liste
ddl.DataBind();
cell.Controls.Add (ddl);
}
else if(c==3)
{
HtmlInputText itqte=new HtmlInputText();
itqte.ID=r+"lc"+c;
itqte.Size=2;
cell.Controls.Add(itqte);
}
else if(c==4)
{
DropDownList stationDifusion = new DropDownList();
stationDifusion.ID=r+"lc"+c;
stationDifusion.Width=100;
//creation d'un array liste
ArrayList station=new ArrayList( );
station.Add("Télévision");
station.Add("Radio RSI");
station.Add("Chaîne Nationale");
station.Add("Dakar FM" );
station.Add("St Louis FM");
station.Add("Louga FM");
station.Add("Thies FM");
station.Add("Kaolack FM");
station.Add("Diourbel FM");
station.Add("Kolda FM");
station.Add("Ziguinchor FM");
station.Add("Tamba FM");
station.Add("Fatick FM");
station.Add("Synchronisation");
stationDifusion.DataSource=station;// fin array liste
stationDifusion.DataBind();
cell.Controls.Add (stationDifusion);
}
else if (c==5)
{
DropDownList ddl = new DropDownList();
DropDownList ddlHeureDifusion = new DropDownList();
ddl.ID=r+"lc"+c;
ddlHeureDifusion.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.Add (ddl);
}
// add the cell to the Cells collection
row.Cells.Add ( cell );
}
// add the row to the Rows collection
Table1.Rows.Add(row);
}
}
}
}
SOS aider mo s'il vous plait je suis dans la ...