01.
<%@ Import
Namespace
=
"system.Data"
%>
02.
<%@ Import
Namespace
=
"system.Data.SqlClient"
%>
03.
04.
<html>
05.
<head><title></title>
06.
<script language=
"vb"
runat=
"server"
>
07.
Dim
ds
As
New
DataSet()
08.
Sub
Page_Load(
ByVal
sender
As
Object
,
ByVal
e
As
EventArgs)
09.
Dim
strConn
As
String
=
"Data Source =.;Database =itedu;Integrated Security = True"
10.
Dim
Conn
As
New
SqlConnection(strConn)
11.
Dim
sql
As
String
=
"SELECT topic,postby,answer FROM topictable"
12.
Dim
adapter
As
New
SqlDataAdapter(sql, Conn)
13.
adapter.Fill(ds,
"topic"
)
14.
BindGrid()
15.
End
Sub
16.
Sub
PageChanged(
ByVal
sender
As
Object
,
ByVal
e
As
GridViewPageEventArgs)
17.
GridView1.PageIndex = e.NewPageIndex
18.
BindGrid()
19.
End
Sub
20.
Sub
BindGrid()
21.
GridView1.DataSource = ds.Tables(
"topic"
)
22.
GridView1.DataBind()
23.
End
Sub
24.
</script>
25.
</head>
26.
<body>
27.
<h2>หัวข้อกระทู้ทั้งหมด</h2>
28.
<form runat=
"server"
ID=
"Form1"
>
29.
<asp:Gridview ID=
"GridView1"
Runat =
"server"
30.
AutoGenerateColumns=
"False"
GridLines=
"None"
31.
AllowPaging=
"True"
PagerStyle-Mode=
"NumericPages"
32.
PagerStyle-PageButtonCount=
"10"
PageSize=
"3"
33.
Width=
"100%"
OnPageIndexChanged=
"PageChanged"
34.
ShowHeader=
"false"
>
35.
<Columns>
36.
<asp:TemplateField>
37.
<ItemTemplate>
38.
<a href=
"Default7.aspx?topicid=<%# DataBinder.Eval(Container.DataItem,"
topicid
")%>"
target =
"_blank"
>
39.
<%#DataBinder.Eval(Container.DataItem,
"topic"
)%> </a>
40.
(<%# DataBinder.Eval(Container.DataItem,
"postby"
)%>)
41.
(<%# DataBinder.Eval(Container.DataItem,
"answer"
)%>)
42.
</ItemTemplate>
43.
</asp:TemplateField>
44.
</Columns>
45.
</asp:Gridview>
46.
</form>
47.
</body>
48.
</html>