2000082805.aspx
-------------------------------------------------------------
path="C:\Inetpub\wwwroot\myASP\tutorials\authors.xml" />
2000082805a.cs
-------------------------------------------------------------
using System;
using System.Data;
using System.IO;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace cjServerControls
{
public class xmlDocReader : Control, INamingContainer
{
string _xmlPath;
string _listID;
string _listValue;
public string Path
{
get { return _xmlPath; }
set { _xmlPath = value; }
}
public string listText
{
get { return _listID; }
set { _listID = value; }
}
public string listValue
{
get {return _listValue; }
set {_listValue = value; }
}
//Were are creating a member here so we can access it throughout the class
DropDownList _DDL;
DataGrid _DG;
FileStream fs;
StreamReader sr;
DataSet ds;
protected override void PreRender()
{
if (Page.IsPostBack) {
DataView dv = new DataView(ds.Tables[0]);
dv.RowFilter = listValue + "='" + _DDL.SelectedItem.Text + "'";
_DG = new DataGrid();
_DG.DataSource = dv;
_DG.DataBind();
Controls.Add(_DG);
}
}
protected override void CreateChildControls()
{
fs = new FileStream(Path, FileMode.Open, FileAccess.Read);
sr = new StreamReader(fs);
ds = new DataSet();
ds.ReadXml(sr);
fs.Close();
_DDL = new DropDownList();
_DDL.DataTextField = listText;
_DDL.DataValueField = listValue;
_DDL.AutoPostBack = true;
_DDL.DataSource = ds.Tables[0].DefaultView;
_DDL.DataBind();
Controls.Add(_DDL);
}
}
}
authors.xml
-------------------------------------------------------------
xmlns:xdo="urn:schemas-microsoft-com:xml-xdo" xdo:DataSetName="DocumentElement">
.
au_id
000-00-0000
Doe
John
foo
One Microsoft Way
Redmond
CA
98005
True
000-00-0123
Millington
John
808 555-5555
One Microsoft Way
Redmond
CA
98005
False
172-32-1176
White
Johnson
408 496-7223
10932 Bigge Rd.
Menlo Park
CA
94025
True
213-46-8915
Green
Marjorie
415 986-7020
309 63rd St. #411
Oakland
CA
94618
True
238-95-7766
Carson
Cheryl
415 548-7723
589 Darwin Ln.
Berkeley
CA
94705
True
267-41-2394
O'Leary
Michael
408 286-2428
22 Cleveland Av. #14
San Jose
CA
95128
True
274-80-9391
Straight
Dean
415 834-2919
5420 College Av.
Oakland
CA
94609
True
341-22-1782
Smith
Meander
913 843-0462
10 Mississippi Dr.
Lawrence
KS
66044
False
409-56-7008
Bennet
Abraham
415 658-9932
6223 Bateman St.
Berkeley
CA
94705
True
427-17-2319
Dull
Ann
415 836-7128
3410 Blonde St.
Palo Alto
CA
94301
True
472-27-2349
Gringlesby
Burt
707 938-6445
PO Box 792
Covelo
CA
95428
True
486-29-1786
Locksley
Charlene
415 585-4620
18 Broadway Av.
San Francisco
CA
94130
True
527-72-3246
Greene
Morningstar
615 297-2723
22 Graybar House Rd.
Nashville
TN
37215
False
648-92-1872
Blotchet-Halls
Reginald
503 745-6402
55 Hillsdale Bl.
Corvallis
OR
97330
True
672-71-3249
Yokomoto
Akiko
415 935-4228
3 Silver Ct.
Walnut Creek
CA
94595
True
712-45-1867
del Castillo
Innes
615 996-8275
2286 Cram Pl. #86
Ann Arbor
MI
48105
True
722-51-5454
DeFrance
Michel
219 547-9982
3 Balding Pl.
Gary
IN
46403
True
724-08-9931
Stringer
Dirk
415 843-2991
5420 Telegraph Av.
Oakland
CA
94609
False
724-80-9391
MacFeather
Stearns
415 354-7128
44 Upland Hts.
Oakland
CA
94612
True
756-30-7391
Karsen
Livia
415 534-9219
5720 McAuley St.
Oakland
CA
94609
True
807-91-6654
Panteley
Sylvia
301 946-8853
1956 Arlington Pl.
Rockville
MD
20853
True
846-92-7186
Hunter
Sheryl
415 836-7128
3410 Blonde St.
Palo Alto
CA
94301
True
893-72-1158
McBadden
Heather
707 448-4982
301 Putnam
Vacaville
CA
95688
False
899-46-2035
Ringer
Anne
801 826-0752
67 Seventh Av.
Salt Lake City
UT
84152
True
998-72-3567
Ringer
Albert
801 826-0752
67 Seventh Av.
Salt Lake City
UT
84152
True
999-99-9999
Toe
John
808 444-4444
21 Microsoft Way
Redwood
CA
98005
False