Remplir une liste déroulant

TmDsbsBs Messages postés 63 Date d'inscription jeudi 22 juillet 2004 Statut Membre Dernière intervention 20 décembre 2004 - 30 juil. 2004 à 14:15
TmDsbsBs Messages postés 63 Date d'inscription jeudi 22 juillet 2004 Statut Membre Dernière intervention 20 décembre 2004 - 3 août 2004 à 11:56
Bonjour.

J'ai créé une ComboBox, j'ai la connexion à ma base SQL, mais je n'arrive pas remplir ma liste. Je ne trouve pas les lignes de commande qui permettent de le faire.

Quelqu'un pourrait-il me les donner ?

Merci !

8 réponses

TmDsbsBs Messages postés 63 Date d'inscription jeudi 22 juillet 2004 Statut Membre Dernière intervention 20 décembre 2004 3
2 août 2004 à 15:48
J'ai rien trouvé de concret sur ce qu tu m'as dit, mais j'ai trouvé d'autres choses. Cependant, mon programme est bien compilé, mais ma liste n'est toujours pas remplie...

Voici mon code :

using System;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.WebPartPages;
using Microsoft.SharePoint.WebControls;
using System.Collections;
using System.IO;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Data.OleDb;

namespace WebPartLibrary1
{
public class WebPart1 : Microsoft.SharePoint.WebPartPages.WebPart
{
// Def des chps qui seront utilisés
DropDownList DDLTest = new DropDownList();

private void ConnectSQL()
{
string strConnexion = "workstation id=SPH-EC98U2MN78X;packet size=4096;integrated security=SSPI;data source=SPH-EC98U2MN78X;persist security info=False;initial catalog=DPSP";
string strRequete = "SELECT ProfessionnelsDeSante FROM ListeTP;";
//	DataSet oDataSet = new DataSet("Liste TP");

SqlConnection oConnection = new SqlConnection(strConnexion);
SqlCommand oCommand = new SqlCommand(strRequete,oConnection);
SqlDataReader dr;
try
{
oConnection.Open();
dr = oCommand.ExecuteReader(CommandBehavior.CloseConnection);
while(dr.Read())
{
DDLTest.Items.Add(new ListItem (dr[0].ToString()));
}
//	DropDownList1.SelectedValueChanged += new EventHandler (DDLTest_SelectedValueChanged);
//	DDLTest.DataSource = "Liste TP";
//	DDLTest.Text = "PROFESSIONNEL DE SANTE";
                //  	DDLTest.Value = "PROFESSIONNEL DE SANTE";
//	oConnection.Close();
}
catch
{}
finally {oConnection.Close();}
}
        
protected override void RenderWebPart(HtmlTextWriter output)
{
foreach (Control ctl in this.Controls)
ctl.RenderControl (output);
}
protected override void CreateChildControls()
{
//		Liste déroulante
Label lblSelectNom = new Label();
lblSelectNom.Font.Bold = true;
lblSelectNom.Text = "Choisissez un nom 
";
this.Controls.Add(lblSelectNom);
this.Controls.Add(DDLTest);

base.CreateChildControls();
}
}
}
1
Rejoignez-nous