01.
public
partial
class
_Default : System.Web.UI.Page
02.
{
03.
protected
void
Page_Load(
object
sender, EventArgs e)
04.
{
05.
06.
if
(!IsPostBack)
07.
{
08.
BindGrid();
09.
}
10.
}
11.
private
void
BindGrid()
12.
{
13.
14.
GridView1.DataSource = GetDataSource();
15.
GridView1.DataBind();
16.
}
17.
18.
protected
DataTable GetDataSource()
19.
{
20.
const
string
key =
"MyDataSource"
;
21.
DataTable Dt = Session[key]
as
DataTable;
22.
informationDataContext z =
new
informationDataContext();
23.
DataSet Ds =
new
DataSet();
24.
if
(Dt ==
null
)
25.
{
26.
Dt =
new
DataTable();
27.
Ds =
new
DataSet();
28.
var query = from a
in
z.jubzs where select a.xml;
29.
var xmlstring = from q
in
query select q.ToString();
30.
foreach
(
string
h
in
xmlstring)
31.
{
32.
System.IO.TextReader Tr =
new
System.IO.StringReader(h);
33.
Ds.ReadXml(Tr);
34.
}
35.
Dt.Columns.Add(
"Name"
,
typeof
(
string
));
36.
Dt.Columns.Add(
"City"
,
typeof
(
string
));
37.
Dt.Columns.Add(
"Age"
,
typeof
(
string
));
38.
Dt = Ds.Tables[0];
39.
Session[key] = Dt;
40.
}
41.
return
Dt;
42.
}
43.
protected
void
GridView1_RowEditing(
object
sender,GridViewEditEventArgs e)
44.
{
45.
GridView1.EditIndex = e.NewEditIndex;
46.
BindGrid();
47.
}
48.
protected
void
GridView1_RowCancelingEdit(
object
sender,
49.
GridViewCancelEditEventArgs e)
50.
{
51.
GridView1.EditIndex = -1;
52.
BindGrid();
53.
}
54.
protected
void
GridView1_RowUpdating(
object
sender,
55.
GridViewUpdateEventArgs e)
56.
{
57.
58.
TextBox cityty = GridView1.Rows[e.RowIndex].FindControl(
"txtCity"
)
as
TextBox;
59.
TextBox ageage = GridView1.Rows[e.RowIndex].FindControl(
"txtAge"
)
as
TextBox;
60.
string
newcity = cityty.Text;
61.
string
newAge = ageage.Text;
62.
DataTable Dt = GetDataSource();
63.
Dt.Rows[e.RowIndex][1] = newcity;
64.
Dt.Rows[e.RowIndex][2] = newAge;
65.
GridView1.EditIndex = -1;
66.
BindGrid();
67.
}
68.
}