IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

ASP.NET Discussion :

OnSelectedIndexChanged dans une listbox


Sujet :

ASP.NET

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    52
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 52
    Par défaut OnSelectedIndexChanged dans une listbox
    Bonjour à tous, j'ai un petit problème avec cet évènement, je m'explique :

    je fais un formulaire dans le quelle est situé une listbox, j'aimerai que lorsque l'utilisateur sélectionne un objet dans cette listbox un tableau soit crée dynamiquement et cela sans avoir à appuyer sur un bouton de type submit.
    Me problème que je rencontre et que lorsque je clique dans ma listebox et que l'index change, rien ne se passe, pourtant la méthode est bien abonnée ( enfin je pense ^^)
    je vous met le code ici :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
     <form runat="server" id="frmtable">
                    <p align="center">
                    Choisissez un état dans la liste                
                    <asp:ListBox ID="list_tri" rows="1" OnSelectedIndexChanged="tableau_prob_load" runat="server" />
                    <br /> 
                    </p>
                    </form>
    et la méthode :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
     
      public void tableau_prob_load(object o, EventArgs e)
        {  
    OdbcConnection connection = new OdbcConnection();
            connection.ConnectionString = ConfigurationManager.ConnectionStrings["maConnexion"].ToString();
     
            try
            {
                connection.Open();           
                OdbcCommand DbcommandEtatId = connection.CreateCommand();
                DbcommandEtatId.CommandText = "Select Etat_id from etat_probleme where Etat_libelle='" + list_tri.SelectedItem.Text +"'";
                OdbcDataReader DbReaderEtatId = DbcommandEtatId.ExecuteReader();
                DbReaderEtatId.Read();
                //Requête pour récuperer le libellé des catégories
                OdbcCommand DbCommand = connection.CreateCommand();
                DbCommand.CommandText = "select * from probleme where Etat_ID='"+DbReaderEtatId.GetInt32(0) +"' order by Etat_ID, Prob_ID;";
                OdbcDataReader DbReader = DbCommand.ExecuteReader();
                while (DbReader.Read())
                {
                    OdbcCommand DbCommandListboxEtat = connection.CreateCommand();
                    DbCommandListboxEtat.CommandText = "select Etat_libelle from etat_probleme";
                    OdbcDataReader DbreaderListBoxEtat = DbCommandListboxEtat.ExecuteReader();
                    HtmlSelect Liste_etat = new HtmlSelect();
                    Liste_etat.Items.Clear();
                    while (DbreaderListBoxEtat.Read())
                    {
                        Liste_etat.Items.Add(DbreaderListBoxEtat.GetString(0));
                    }
                    HtmlTableRow ma_ligne_prob = new HtmlTableRow();
                    HtmlTableCell ma_cellule_num_prob = new HtmlTableCell();
                    HtmlTableCell ma_cellule_titre_prob = new HtmlTableCell();
                    HtmlTableCell ma_cellule_cat_prob = new HtmlTableCell();
                    HtmlTableCell ma_cellule_os_prob = new HtmlTableCell();
                    HtmlTableCell ma_cellule_mod_prob = new HtmlTableCell();
                    HtmlTableCell ma_cellule_msg_prob = new HtmlTableCell();
                    HtmlTableCell ma_cellule_etat_prob = new HtmlTableCell();
                    HtmlTableCell ma_cellule_modif_etat = new HtmlTableCell();
                    HyperLink link_titre = new HyperLink();
                    link_titre.Text = DbReader.GetString(1);
                    link_titre.NavigateUrl = "forumA_show_topic.aspx?ref_prob=" + DbReader.GetInt32(0);
                    ma_cellule_titre_prob.Controls.Add(link_titre);
                    ma_cellule_num_prob.InnerText = DbReader.GetInt32(0).ToString();
                    OdbcCommand DbCommandCat = connection.CreateCommand();
                    DbCommandCat.CommandText = "select lib_liste_lib from libelle_liste where  Categorie_Num='2' and  Lib_Liste_num=" + DbReader.GetInt32(6);
                    OdbcDataReader DbReaderCat = DbCommandCat.ExecuteReader();
                    DbReaderCat.Read();
                    ma_cellule_cat_prob.InnerText = DbReaderCat.GetString(0);
                    OdbcCommand DbCommandOs = connection.CreateCommand();
                    DbCommandOs.CommandText = "select lib_liste_lib from libelle_liste where  Categorie_Num='1' and  Lib_Liste_num=" + DbReader.GetInt32(7);
                    OdbcDataReader DbReaderOs = DbCommandOs.ExecuteReader();
                    DbReaderOs.Read();
                    ma_cellule_os_prob.InnerText = DbReaderOs.GetString(0);
                    OdbcCommand DbCommandMod = connection.CreateCommand();
                    DbCommandMod.CommandText = "select lib_liste_lib from libelle_liste where  Categorie_Num='3' and  Lib_Liste_num=" + DbReader.GetInt32(8);
                    OdbcDataReader DbReaderMod = DbCommandMod.ExecuteReader();
                    DbReaderMod.Read();
                    ma_cellule_mod_prob.InnerText = DbReaderMod.GetString(0);
                    ma_cellule_msg_prob.InnerText = DbReader.GetString(3);
                    OdbcCommand DbCommandEtat = connection.CreateCommand();
                    DbCommandEtat.CommandText = "Select etat_libelle from etat_probleme where Etat_id=" + DbReader.GetInt32(15);
                    OdbcDataReader DbReaderEtat = DbCommandEtat.ExecuteReader();
                    DbReaderEtat.Read();
                    ma_cellule_etat_prob.InnerText = DbReaderEtat.GetString(0);
                    ma_cellule_modif_etat.Controls.Add(Liste_etat);
                    ma_cellule_num_prob.Width = "7%";
                    ma_cellule_titre_prob.Width = "13%";
                    ma_cellule_cat_prob.Width = "7%";
                    ma_cellule_os_prob.Width = "9%";
                    ma_cellule_mod_prob.Width = "7%";
                    ma_cellule_msg_prob.Width = "40%";
                    ma_cellule_etat_prob.Width = "7%";
                    ma_cellule_modif_etat.Width = "10%";
                    ma_cellule_num_prob.BgColor = "#EFEFDD";
                    ma_cellule_titre_prob.BgColor = "#EFEFDD";
                    ma_cellule_cat_prob.BgColor = "#EFEFDD";
                    ma_cellule_os_prob.BgColor = "#EFEFDD";
                    ma_cellule_mod_prob.BgColor = "#EFEFDD";
                    ma_cellule_msg_prob.BgColor = "#EFEFDD";
                    ma_cellule_etat_prob.BgColor = "#EFEFDD";
                    ma_cellule_modif_etat.BgColor = "#EFEFDD";
                    ma_cellule_num_prob.Align = "center";
                    ma_cellule_titre_prob.Align = "center";
                    ma_cellule_cat_prob.Align = "center";
                    ma_cellule_os_prob.Align = "center";
                    ma_cellule_mod_prob.Align = "center";
                    ma_cellule_msg_prob.Align = "center";
                    ma_cellule_etat_prob.Align = "center";
                    ma_cellule_modif_etat.Align = "center";
                    ma_ligne_prob.Cells.Add(ma_cellule_num_prob);
                    ma_ligne_prob.Cells.Add(ma_cellule_titre_prob);
                    ma_ligne_prob.Cells.Add(ma_cellule_cat_prob);
                    ma_ligne_prob.Cells.Add(ma_cellule_os_prob);
                    ma_ligne_prob.Cells.Add(ma_cellule_mod_prob);
                    ma_ligne_prob.Cells.Add(ma_cellule_msg_prob);
                    ma_ligne_prob.Cells.Add(ma_cellule_etat_prob);
                    ma_ligne_prob.Cells.Add(ma_cellule_modif_etat);
                    Prob_table.Rows.Add(ma_ligne_prob);
                }  
                 connection.Close();
            }
            catch (Exception ex)
            {
                lblerror.Text = ex.Message;
            }
    }
    Je vous remercie d'avance.

  2. #2
    Membre confirmé
    Profil pro
    azeazeae
    Inscrit en
    Septembre 2002
    Messages
    114
    Détails du profil
    Informations personnelles :
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : azeazeae

    Informations forums :
    Inscription : Septembre 2002
    Messages : 114
    Par défaut
    Tu as une propriete sur la listbox :autopostback : la mettre a true.

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    52
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 52
    Par défaut
    merci beaucoup ça marche ^^

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. recherche dans une listbox
    Par micknic dans le forum Balisage (X)HTML et validation W3C
    Réponses: 4
    Dernier message: 23/02/2005, 21h39
  2. Clique droit dans une ListBox
    Par LoicH dans le forum C++Builder
    Réponses: 5
    Dernier message: 07/02/2005, 22h50
  3. [debutant] supprimer elements dans une listbox
    Par F.F. dans le forum C++Builder
    Réponses: 8
    Dernier message: 02/07/2004, 11h38
  4. [WIN32]tabulation dans une listbox
    Par stoluup dans le forum MFC
    Réponses: 2
    Dernier message: 09/06/2004, 10h11
  5. Icône a coté du texte dans une ListBox
    Par joce3000 dans le forum C++Builder
    Réponses: 6
    Dernier message: 05/12/2003, 02h25

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo