Followers

Friday, 18 January 2013

asp.net XmlDataSource: how to use

XmlDataSource.aspx
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="XmlDataSource.aspx.cs" Inherits="XmlDataSource" %>  
  2.   
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  4.   
  5. <html xmlns="http://www.w3.org/1999/xhtml">  
  6. <head runat="server">  
  7.     <title>asp.net XmlDataSource: how to use</title>  
  8. </head>  
  9. <body>  
  10.     <form id="form1" runat="server">  
  11.     <div>  
  12.         <h2 style="color:Teal">XmlDataSource</h2>  
  13.         <asp:CheckBoxList   
  14.             ID="CheckBoxList1"  
  15.             runat="server"  
  16.             >  
  17.         </asp:CheckBoxList>  
  18.         <asp:XmlDataSource   
  19.             ID="XmlDataSource1"  
  20.             runat="server"  
  21.             >  
  22.             <Data>  
  23.                 <Employees>  
  24.                     <Employee ID="1" Name="John" />  
  25.                     <Employee ID="1" Name="Jim" />  
  26.                     <Employee ID="1" Name="Jones" />  
  27.                     <Employee ID="1" Name="Jenny" />  
  28.                     <Employee ID="1" Name="Ben" />  
  29.                 </Employees>  
  30.             </Data>  
  31.         </asp:XmlDataSource>  
  32.     </div>  
  33.     </form>  
  34. </body>  
  35. </html>  
XmlDataSource.aspx.cs

  1. using System;  
  2. using System.Collections;  
  3. using System.Configuration;  
  4. using System.Data;  
  5. using System.Linq;  
  6. using System.Web;  
  7. using System.Web.Security;  
  8. using System.Web.UI;  
  9. using System.Web.UI.HtmlControls;  
  10. using System.Web.UI.WebControls;  
  11. using System.Web.UI.WebControls.WebParts;  
  12. using System.Xml.Linq;  
  13.   
  14. public partial class XmlDataSource : System.Web.UI.Page  
  15. {  
  16.     protected void Page_Load(object sender, EventArgs e)  
  17.     {  
  18.         if(!this.IsPostBack)  
  19.         {  
  20.             CheckBoxList1.DataSourceID = "XmlDataSource1";  
  21.             CheckBoxList1.DataTextField = "Name";  
  22.             CheckBoxList1.DataValueField = "ID";  
  23.             CheckBoxList1.RepeatColumns = 3;  
  24.             CheckBoxList1.BorderWidth = 2;  
  25.             CheckBoxList1.BorderColor = System.Drawing.Color.DarkGreen;  
  26.             CheckBoxList1.BackColor = System.Drawing.Color.Green;  
  27.             CheckBoxList1.ForeColor = System.Drawing.Color.White;  
  28.         }  
  29.     }  
  30. }  


No comments:

Post a Comment