Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

AFFICHER LE CONTENU D'UN FICHIER XML VIA UN CONTRÔLE DATAGRID


Information sur la source

Catégorie :ASP.Net Source .NET ( DotNet ) Niveau : Initié Date de création : 24/05/2002 Date de mise à jour : 24/05/2002 18:55:06 Vu / téléchargé: 10 770 / 462

Note :
9 / 10 - par 1 personne
9,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

Commentaire sur cette source (1)
Ajouter un commentaire et/ou une note

Description

Voici un petit bout de code pour afficher des données XML dans un contrôle de type DATAGRID...    
 

Source

  • <%@ Page Language="VB" %>
  • <%@ Import Namespace="System.Xml" %>
  • <%@ Import Namespace="System.Data" %>
  • <%@ Import Namespace="System.Data.OleDb" %>
  • <script runat=server>
  • private i, j as integer
  • private strOutput as string = ""
  • sub Page_Load(obj as object, e as eventargs)
  • dim xmldoc as new XMLDataDocument()
  • try
  • xmldoc.DataSet.ReadXml(Server.MapPath("film.xml"))
  • DataGrid1.DataSource = xmldoc.DataSet
  • DataGrid1.DataMember = xmldoc.DataSet.Tables(0).TableName
  • DataGrid1.DataBind()
  • catch ex as Exception
  • strOutput = "Impossible d'accéder au fichier XML"
  • end try
  • output.Text = strOutput
  • end sub
  • </script>
  • <html>
  • <body>
  • <asp:Label id="output" runat="server" />
  • <asp:DataGrid id="DataGrid1" runat="server"
  • BorderColor="black"
  • GridLines="Vertical"
  • cellpadding="4"
  • cellspacing="0"
  • width="450"
  • Font-Name="Arial"
  • Font-Size="8pt"
  • HeaderStyle-BackColor="#cc9966"
  • FooterStyle-BackColor="#cccc99"
  • ItemStyle-BackColor="#ffffff"
  • AlternatingItemStyle-Backcolor="#cccccc" />
  • </body>
  • </html>
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>

<script runat=server>
	private i, j as integer
	private strOutput as string = ""
   
   	sub Page_Load(obj as object, e as eventargs)
      	dim xmldoc as new XMLDataDocument()
         
      	try
         	xmldoc.DataSet.ReadXml(Server.MapPath("film.xml"))
         
         	DataGrid1.DataSource = xmldoc.DataSet
         	DataGrid1.DataMember = xmldoc.DataSet.Tables(0).TableName
         
         	DataGrid1.DataBind()
         
        catch ex as Exception
           	strOutput = "Impossible d'accéder au fichier XML"
      	end try
      
      	output.Text = strOutput
	end sub
</script>

<html>
<body>
   <asp:Label id="output" runat="server" />
   
   <asp:DataGrid id="DataGrid1" runat="server" 
         BorderColor="black" 
         GridLines="Vertical" 
         cellpadding="4" 
         cellspacing="0" 
         width="450"
         Font-Name="Arial" 
         Font-Size="8pt" 
         HeaderStyle-BackColor="#cc9966"
         FooterStyle-BackColor="#cccc99"
         ItemStyle-BackColor="#ffffff"
         AlternatingItemStyle-Backcolor="#cccccc" />
</body>
</html>     

Conclusion

Allez bon courage et bonne programmation !!!!!    
 

Fichier Zip

Pour les "Membres Club", vous pouvez télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip

Commentaires et avis

signaler à un administrateur
Commentaire de tripmagic le 07/09/2008 21:00:29

simple et efficace

Ajouter un commentaire



Nos sponsors

Sondage...

CalendriCode

Novembre 2008
LMMJVSD
     12
3456789
10111213141516
17181920212223
24252627282930

Consulter la suite du CalendriCode



Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel BAÏSE, Merci à Vincent pour ses précieux conseils
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés
Temps d'éxécution de la page : 0,374 sec

Google Coop CodeS-SourceS Google Coop CodeS-SourceS


Certaines images présentes sur le site (notament certains avatars) sont issues des collections IconShock, donc si vous souhaitez utiliser ces icons vous devez les acheter, ne les copiez pas et ne utilisez pas dans vos sites et applications sans les avoir commandé.