473,385 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Creating Handler for Dynamic DropDownList

Hie,
I create a dynamique HtmlTable, in each cell of this HtmlTable put a new control ( dropdownlist,label,..) 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.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;
protected System.Web.UI.WebControls.DropDownList xclient;
protected System.Web.UI.WebControls.TextBox xnbre;
protected System.Web.UI.HtmlControls.HtmlTable Table1;

private void Page_Load(object sender, System.EventArgs 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.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.xnbre.TextChanged += new System.EventHandler(this.xnbre_TextChanged);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void xnbre_TextChanged(object sender, System.EventArgs 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.SelectedIndexChanged += new System.EventHandler(this.stationDifusion_SelectedI ndexChanged);//
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==2)
{
DropDownList ddl = new DropDownList();
ddl.ID="hd"+r+"";
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==6)
{
DropDownList ddl = new DropDownList();
DropDownList ddlHeureDifusion = new DropDownList();
ddlHeureDifusion.ID="maj"+r+"";
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);
}
else if(c==0)
{
string sql_query="select nom_prod,pu from produit order by nom_prod asc";
//cell.Controls.Add ( new HtmlInputText());

DropDownList ddlDesi = new DropDownList();
DropDownList ddlPU = new DropDownList();
//************************************************** *
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.Size=10;
cell.Controls.Add(itnom);
}
else if(c==3)
{
HtmlInputText itqte=new HtmlInputText();
itqte.Size=2;

cell.Controls.Add(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.
Nov 22 '05 #1
0 1554

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: DotNetJunkies User | last post by:
Hie, I create a dynamique HtmlTable, in each cell of this HtmlTable put a new control ( dropdownlist,label,..) and then want to create handler so that if i change the select item in the dop downlist...
5
by: DC Gringo | last post by:
I've got a command button to submit a value from a dropdown list that should then filter a SELECT query. I'm simply appending a WHERE colx = <variableSelectedFromDropdownList>. How do I pass this...
5
by: mytestemailaccount | last post by:
Hi, Hope you can help. I am relatively new to all this but would appreciate the groups help. The scenario: I am c# and asp.net to create a web application. The web page contains a user...
2
by: Patrick | last post by:
I want to define a set of web-form templates in XML and render the equivalent web-form with ASP.NET, then process any input server controls on the form. Reading the XML file from Page_load is...
4
by: TS | last post by:
I am creating a User control and i create some dynamic controls in the init handler. one of the controls is a custom validator which i assign a serverValidate event handler. I usally always do my...
9
by: Tarscher | last post by:
hi all, I have this seemingly simple problem. I have lost a lot of time on it though. When a user selects a value from a dropdownlist (static control) a dynamic control is generated. I have...
2
by: John Kotuby | last post by:
Hi guys, I am converting a rather complicated database driven Web application from classic ASP to ASP.NET 2.0 using VB 2005 as the programming language. The original ASP application works quite...
0
by: imranabdulaziz | last post by:
hi all , i am mess with the one situation. i am using asp.net2.0 ,C# and sql server 2005. I have checkboxlist and based on user selection i creates dynamic controls(which code is in...
5
by: smithak82 | last post by:
I am tring to create n number of dropdown list.each have the same content. In this way i am able to create the dropdownlist but when the post back happens on the page the dropdownlist vanishes. so...
6
by: shashi shekhar singh | last post by:
Respected Sir, I have to create multiple dynamic dropdownlist boxes and add items dynamically in <asp:table> server control but problem occurs , i.e. except of fist dropdown list no dropdownlist...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.