Problème insertion code C# au sein de code HTLM de .aspx
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:
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
|
<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>
...
.....
...... |
Ce code m'a donné cet erreur:
Citation:
Message d'erreur de l'analyseur: 'TabPanel_<%= idMagasin %>' n'est pas un identificateur valide.
J'ai enlevé idmagasin comme ceci:
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
|
<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>
...
.....
...... |
Aussi, le code ci-dessus m'a donné cette exception:
Citation:
System.ArgumentException: Une entrée avec la même clé existe déjà.
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.
Merci pour toute aide donnée.