Bonjour,
J'ai un problème dont je n'ai pas trouvé une solution, concernant l'insertion de code C# dans le code HTMl de .aspx
Je veux faire une boucle sur la balise <ajaxToolkit:TabPanel de <ajaxToolkit:TabContainer pour avoir plusieurs onglets selon un petit nombre de données existant dans une table DB.
Voici un moceau de mon code:
Ce code m'a donné cet erreur:
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 <ajaxToolkit:TabContainer ID="TabContainerMagasin" runat="server" ActiveTabIndex="0"> <% // Lire la chaîne de connexion à partir de Web.config ConnectionStringSettings connex = ConfigurationManager.ConnectionStrings["ConnectionString1"]; string connectString = connex.ConnectionString; // Objet connection System.Data.SqlClient.SqlConnection connection = new System.Data.SqlClient.SqlConnection(connectString); // SqlCommand System.Data.SqlClient.SqlCommand commandMagasins = new System.Data.SqlClient.SqlCommand("select idmagasin, nommagasin from magasin", connection); // Ouverture connection.Open(); // Objet DataReader System.Data.SqlClient.SqlDataReader reader = commandMagasins.ExecuteReader(); while (reader.Read()) { if (reader["nommagasin"] != System.DBNull.Value) { string nomMagasin = (string)reader["nommagasin"]; int idMagasin = (int)reader["idmagasin"]; %> <ajaxToolkit:TabPanel ID="TabPanel_<%= idMagasin%>" runat="server" HeaderText="<%= nomMagasin %>"> <ContentTemplate> ... ..... ......
J'ai enlevé idmagasin comme ceci:Message d'erreur de l'analyseur: 'TabPanel_<%= idMagasin %>' n'est pas un identificateur valide.
Aussi, le code ci-dessus m'a donné cette exception:
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 <ajaxToolkit:TabContainer ID="TabContainerMagasin" runat="server" ActiveTabIndex="0"> <% // Lire la chaîne de connexion à partir de Web.config ConnectionStringSettings connex = ConfigurationManager.ConnectionStrings["ConnectionString1"]; string connectString = connex.ConnectionString; // Objet connection System.Data.SqlClient.SqlConnection connection = new System.Data.SqlClient.SqlConnection(connectString); // SqlCommand System.Data.SqlClient.SqlCommand commandMagasins = new System.Data.SqlClient.SqlCommand("select idmagasin, nommagasin from magasin", connection); // Ouverture connection.Open(); // Objet DataReader System.Data.SqlClient.SqlDataReader reader = commandMagasins.ExecuteReader(); while (reader.Read()) { if (reader["nommagasin"] != System.DBNull.Value) { string nomMagasin = (string)reader["nommagasin"]; //int idMagasin = (int)reader["idmagasin"]; %> <ajaxToolkit:TabPanel ID="TabPanel_" runat="server" HeaderText="<%= nomMagasin %>"> <ContentTemplate> ... ..... ......
Le résultat c'est que j'ai trouvé un grand problème pour insérer un code C# dans le code HTMl de .aspx contrairement aus autres langages comme PHP.System.ArgumentException: Une entrée avec la même clé existe déjà.
Merci pour toute aide donnée.
Partager