ASP.NET e Xml – Codice sorgente dell’esempio

Sorgenti: LeggiXml.aspx

Scarica i sorgenti: aspnet11.zip

Articolo a cui si riferisce il codice: ASP.NET e Xml

LeggiXml.aspx

  1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3 
  4 <%@ Page Language="VB" Debug="True" %>
  5 
  6 <%@ Import Namespace="System.Data" %>
  7 <%@ Import Namespace="System.Data.OleDb" %>
  8 
  9 <%@ Register TagPrefix="ANet" TagName="Footer" Src="includes/footer.ascx"%>
 10 
 11 <!
 12 # nome: XMLLeggi.aspx
 13 # scritto da: Antonio Volpon
 14 # data creazione: 23 Novembre 2001
 15 # ultima modifica: 23 Novembre 2001
 16 # copyright: Antonio Volpon
 17 >
 18 
 19 <script language="vb" runat="server">
 20 
 21 Sub CaricaXml()
 22   
 23   Dim objDataSet As New DataSet()
 24   Dim objTableLibro As DataTable
 25   Dim objTableView As DataView
 26   
 27   Dim strUrlPath As String
 28   Dim strLocPath As String
 29   
 30   strUrlPath = Left(Request.Path,InStrRev(Request.FilePath,"/")) & "Xml/"
 31   
 32   strLocPath = Request.MapPath(strUrlPath)
 33   
 34   objDataSet.ReadXmlSchema(strLocPath & "XmlSchema.xml")
 35 
 36   risposta.innerHtml += "Caricato il file <a target=‘_blank’ href=’"& strUrlPath & "XmlSchema.xml’>" & strUrlPath & "XmlSchema.xml</a><br>"
 37 
 38   objDataSet.ReadXml(strLocPath & "XmlDocument.xml")
 39   
 40   risposta.innerHtml += "Caricato il file <a target=‘_blank’ href=’"& strUrlPath & "XmlDocument.xml’>" & strUrlPath & "XmlDocument.xml</a><br>"
 41   
 42   objTableLibro = objDataSet.Tables("Libro")
 43     
 44   objTableView = objTableLibro.DefaultView
 45   
 46   libri.DataSource = objTableView
 47   libri.DataBind()
 48   
 49 End Sub
 50 
 51 Sub Change_Index(objSender As Object, objArgs As DataGridPageChangedEventArgs)
 52 
 53   libri.CurrentPageIndex = objArgs.NewPageIndex
 54   CaricaXml()  
 55   
 56 End Sub
 57   
 58 Sub Page_Load()
 59 
 60   If Not Page.IsPostBack() Then
 61 
 62     CaricaXml()          
 63   
 64   End If
 65 
 66 End Sub
 67 
 68 </script>
 69 
 70 <html>
 71 
 72   <head>
 73     <link rel="stylesheet" href="css/aspnet.css" type="text/css">
 74     </link>
 75     <title>Da XML a DataSet</title>    
 76   </head>
 77   
 78   <body>
 79     <div class="titolo">
 80       Da XML a DataSet
 81     </div>
 82     
 83     <hr noshade="true" size="1" width="100%">  
 84     
 85     <center>
 86     
 87     <form runat="server">
 88     
 89  <asp:DataGrid id="libri" runat="server"
 90  AutoGenerateColumns="False"
 91  HeaderStyle-BackColor="#CCCCCC"
 92  HeaderStyle-HorizontalAlign="center"
 93  Width="80%"
 94  AllowPaging="True"
 95  PageSize="10"
 96  PagerStyle-HorizontalAlign="Right"
 97  PagerStyle-Mode="NumericPages"
 98  OnPageIndexChanged="Change_Index"
 99  AllowSorting="True">

100      
101       <SelectedItemStyle BackColor="Yellow"></SelectedItemStyle>
102       <AlternatingItemStyle BackColor="LightGreen"></AlternatingItemStyle>     
103       <Columns>
104 
105         <asp:TemplateColumn HeaderText="Seleziona" ItemStyle-HorizontalAlign="Center">
106           <ItemTemplate>
107             <asp:Button CommandName="Select" Text="x" runat="server" />
108           </ItemTemplate>
109         </asp:TemplateColumn>
110   
111         <asp:BoundColumn DataField="IdLibro" HeaderText="Id" ItemStyle-HorizontalAlign="Left" SortExpression="IdLibro" ReadOnly="True"/>
112         
113         <asp:TemplateColumn HeaderText="Titolo" ItemStyle-HorizontalAlign="Left" SortExpression="Titolo">
114           <ItemTemplate>
115             <%# Container.DataItem("Titolo")%>  
116           </ItemTemplate>
117           <EditItemTemplate>
118             <asp:TextBox id="titolo" text=’<%# Container.DataItem("Titolo") %>‘ runat="server"/>
119             <asp:RequiredFieldValidator ControlToValidate="titolo" Display="Dynamic" runat="server" >
120               Valore obbligatorio
121             </asp:RequiredFieldValidator>            
122           </EditItemTemplate>          
123         </asp:TemplateColumn>
124         
125         <asp:BoundColumn DataField="EdizioneAnno" HeaderText="Anno" ItemStyle-HorizontalAlign="Left" SortExpression="EdizioneAnno" />
126         <asp:BoundColumn DataField="Collana" HeaderText="Collana" ItemStyle-HorizontalAlign="Left" SortExpression="Collana" />
127         
128       </Columns>
129 
130    </asp:DataGrid>
131     
132     <div id="risposta" class="txt" runat="server" EnableViewState="false"></div>
133 
134     </form>
135 
136     </center>
137 
138  <ANet:Footer id="Menu" runat="server" />
139     
140   </body>
141   
142 </html>