Friday, August 13, 2010




XmlDataSource.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="XmlDataSource.aspx.cs" Inherits="XmlDataSource" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>asp.net XmlDataSource: how to use</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:Teal">XmlDataSource</h2>
<asp:CheckBoxList
ID="CheckBoxList1"
runat="server"
>
</asp:CheckBoxList>
<asp:XmlDataSource
ID="XmlDataSource1"
runat="server"
>
<Data>
<Employees>
<Employee ID="1" Name="John" />
<Employee ID="1" Name="Jim" />
<Employee ID="1" Name="Jones" />
<Employee ID="1" Name="Jenny" />
<Employee ID="1" Name="Ben" />
</Employees>
</Data>
</asp:XmlDataSource>
</div>
</form>
</body>
</html>

XmlDataSource.aspx.cs

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class XmlDataSource : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!this.IsPostBack)
{
CheckBoxList1.DataSourceID = "XmlDataSource1";
CheckBoxList1.DataTextField = "Name";
CheckBoxList1.DataValueField = "ID";
CheckBoxList1.RepeatColumns = 3;
CheckBoxList1.BorderWidth = 2;
CheckBoxList1.BorderColor = System.Drawing.Color.DarkGreen;
CheckBoxList1.BackColor = System.Drawing.Color.Green;
CheckBoxList1.ForeColor = System.Drawing.Color.White;
}
}
}

No comments: