01.
using
System;
02.
using
System.Collections.Generic;
03.
using
System.Linq;
04.
using
System.Web;
05.
using
System.Web.UI;
06.
using
System.Web.UI.WebControls;
07.
using
System.IO;
08.
using
System.Xml;
09.
10.
using
System.Data;
11.
12.
public
partial
class
_Default : System.Web.UI.Page
13.
{
14.
protected
void
Page_Load(
object
sender, EventArgs e)
15.
{
16.
if
(!IsPostBack)
17.
{
18.
19.
XmlDocument xDoc =
new
XmlDocument();
20.
XmlDeclaration xDeclaration = xDoc.CreateXmlDeclaration(
"1.0"
,
null
,
null
);
21.
xDoc.AppendChild(xDeclaration);
22.
23.
XmlElement rootNode = xDoc.CreateElement(
"ข้อมูลของคุณจิงโจ้_จะสุ่มเอานะคะ"
);
24.
Random rnd =
new
Random(System.DateTime.Now.Millisecond);
25.
for
(
int
i = 0; i < 10; i++)
26.
{
27.
string
runningNoStr = (i + 1).ToString(
"000"
);
28.
29.
string
_NameStr =
string
.Empty.PadLeft(
4, (
char
)rnd.Next(
'A'
,
'Z'
));
30.
string
_AgeStr = rnd.Next(18, 40).ToString();
31.
32.
rootNode.SetAttribute(
"ชื่อที่_"
+ runningNoStr, _NameStr);
33.
rootNode.SetAttribute(
"อายุที่_"
+ runningNoStr, _AgeStr);
34.
}
35.
36.
xDoc.AppendChild(rootNode);
37.
38.
MemoryStream xmlStream =
new
MemoryStream();
39.
40.
xDoc.Save(xmlStream);
41.
42.
xmlStream.Flush();
43.
xmlStream.Position = 0;
44.
45.
46.
DataSet bindData =
new
DataSet();
47.
bindData.ReadXml(xmlStream);
48.
49.
GridView1.DataSource = bindData;
50.
GridView1.DataBind();
51.
}
52.
}
53.
}