Précédent   Forum du club des développeurs et IT Pro > Dotnet > Développement Web avec .NET > ASP.NET
ASP.NET ASP.NET -Forum d'entraide sur le Développement Web en ASP.NET. Avant de poster -> FAQ ASP.NET, Articles ASP.NET
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse
 
Outils de la discussion
Publicité
'
Vieux 09/01/2013, 14h23   #1
gunners16
Invité de passage
 
Homme Arnaud Mwizero
Bujumbura
Inscription : novembre 2012
Messages : 1
Détails du profil
Informations personnelles :
Nom : Homme Arnaud Mwizero
Localisation : Burundi

Informations professionnelles :
Activité : Bujumbura
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : novembre 2012
Messages : 1
Points : 0
Points : 0
Par défaut Problème avec dropdownlist

Bonjour à tous.je commence à programmer avec C#Asp.net et j'ai un problème avec le dropdownlist.Je récupère les données de la BD mais je n'arrive pas à cacher l'identifiant de la table lorsque je compile ma page. voici le code en soit:

Code :
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
using System; 
using System.Collections; 
using System.Configuration; 
using System.Data; 
using System.Web; 
using System.Web.Security; 
using System.Web.UI; 
using System.Web.UI.HtmlControls; 
using System.Web.UI.WebControls; 
using System.Web.UI.WebControls.WebParts; 
using System.Data.SqlClient; 
 
namespace memoire 
{ 
public partial class frequentation : System.Web.UI.Page 
{ 
protected void Page_Load(object sender, EventArgs e) 
{ 
DropDownList1.Items.GetEnumerator(); 
String con = "Data source=localhost;Initial catalog=concours;uid=mwizero;pwd=mwizero"; 
SqlConnection connection = new SqlConnection(con); 
String req = " select idcandidat,Code_candidat,Nom_candidat,Prenom_candidat from candidat "; 
connection.Open(); 
SqlCommand reqcom = new SqlCommand(req, connection); 
SqlDataReader der = reqcom.ExecuteReader(); 
while (der.Read()) 
DropDownList1.Items.Add(der.GetInt32(0).ToString() + "- " + der.GetString(1) + " -" + der.GetString(2) + " -" + der.GetString(3)); 
connection.Close(); 
 
}
J'aimerai savoir comment je pourrai seulement le cacher au moment de la compilation car c'est cet identifiant que je vais insérer dans une autre tableau relation.
Merci de vos réponses
gunners16 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 09/01/2013, 15h09   #2
maradona_9
Membre à l'essai
 
Homme mohammed dghoughi
Développeur .NET
Inscription : mars 2011
Messages : 21
Détails du profil
Informations personnelles :
Nom : Homme mohammed dghoughi
Localisation : Maroc

Informations professionnelles :
Activité : Développeur .NET
Secteur : Finance

Informations forums :
Inscription : mars 2011
Messages : 21
Points : 21
Points : 21
J'ai pas bien compris ms comment cacher l'identifiant de la table???
veut-tu dire de n'afficher pas l'idantifiant de la table condidat dans les items de dropdownlist????
maradona_9 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 09/01/2013, 18h26   #3
stroumfs
Membre habitué
 
Inscription : octobre 2006
Messages : 204
Détails du profil
Informations forums :
Inscription : octobre 2006
Messages : 204
Points : 142
Points : 142
Si le problème est de récupérer la valeur en question, ton problème viens du fait que la source de données attribué à ton dropdown est fait à chaque chargement de ta page.

Pour résoudre le problème il faut le faire uniquement au premier chargement sois de la manière suivante :
Code :
1
2
3
4
5
 
if(!IsPostBack)
{
//Ton datasource ici
}
Dans le cas où celui-ci serait mit à jour par un autre contrôle, il faut le faire sur demande à ce moment.

En espérant que cela puisse t'aider.
stroumfs est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 10/01/2013, 11h38   #4
bossun
Membre Expert
 
Avatar de bossun
 
Inscription : novembre 2002
Messages : 1 332
Détails du profil
Informations personnelles :
Âge : 30

Informations forums :
Inscription : novembre 2002
Messages : 1 332
Points : 1 250
Points : 1 250
Voilà comment remplir correctement ta DropDownList


http://www.codersource.net/AspNet/As...tinASPNet.aspx

Cordialement
__________________
il vaut mieux prendre son pied que de se prendre la tête!!

http://bossun.noxblog.com
bossun est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/01/2013, 19h56   #5
Shadam
Membre éprouvé
 
Homme
Développeur .NET
Inscription : mars 2011
Messages : 449
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France, Ille et Vilaine (Bretagne)

Informations professionnelles :
Activité : Développeur .NET
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : mars 2011
Messages : 449
Points : 448
Points : 448
[code]
Code :
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
 
using System; 
using System.Collections; 
using System.Configuration; 
using System.Data; 
using System.Web; 
using System.Web.Security; 
using System.Web.UI; 
using System.Web.UI.HtmlControls; 
using System.Web.UI.WebControls; 
using System.Web.UI.WebControls.WebParts; 
using System.Data.SqlClient; 
 
namespace memoire 
{ 
public partial class frequentation : System.Web.UI.Page 
{ 
protected void Page_Load(object sender, EventArgs e) 
{ 
DropDownList1.Items.GetEnumerator(); 
String con = "Data source=localhost;Initial catalog=concours;uid=mwizero;pwd=mwizero"; 
SqlConnection connection = new SqlConnection(con); 
String req = " select idcandidat,Code_candidat,Nom_candidat,Prenom_candidat from candidat "; 
connection.Open(); 
SqlCommand reqcom = new SqlCommand(req, connection); 
SqlDataReader der = reqcom.ExecuteReader(); 
List(Of candidat) maListe = new List(Of candidat);
Candidat currenrObject;
while (der.Read())
{
currentObject = new Candidat;
currentObject.Id = der.GetInt32(0);
currentObject.Code = der.GetString(1);
currentObject.Nom = der.GetString(2);
currentObject.Prenom = der.GetString(3);
maListe.Add(currentObject);
}
connection.Close(); 
 
DropDownList1.DataSource = maListe;
DropDownList1.DataValueField = "Id";
DropDownList1.DataTextField = "Code";
 
}
 
Private class Candidat
{
int Id;
string Code;
string Nom;
string Prenom;
 
// le code de génération de ta classe
}
Shadam est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse
Outils de la discussion

Navigation rapide


Fuseau horaire GMT +2. Il est actuellement 19h55.


 
 
 
 
Partenaires

Hébergement Web