<%@ Import Namespace = "system.Data"%>
<%@ Import Namespace = "system.Data.SqlClient"%>
<html>
<head><title></title>
<script language="vb" runat="server">
Dim ds As New DataSet()
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim strConn As String = "Data Source =.;Database =itedu;Integrated Security = True"
Dim Conn As New SqlConnection(strConn)
Dim sql As String = "SELECT topic,postby,answer FROM topictable"
Dim adapter As New SqlDataAdapter(sql, Conn)
adapter.Fill(ds, "topic")
BindGrid()
End Sub
Sub PageChanged(ByVal sender As Object, ByVal e As GridViewPageEventArgs)
GridView1.PageIndex = e.NewPageIndex
BindGrid()
End Sub
Sub BindGrid()
GridView1.DataSource = ds.Tables("topic")
GridView1.DataBind()
End Sub
</script>
</head>
<body>
<h2>หัวข้อกระทู้ทั้งหมด</h2>
<form runat="server" ID="Form1">
<asp:Gridview ID= "GridView1" Runat ="server"
AutoGenerateColumns="False" GridLines="None"
AllowPaging="True" PagerStyle-Mode="NumericPages"
PagerStyle-PageButtonCount="10" PageSize="3"
Width="100%" OnPageIndexChanged= "PageChanged"
ShowHeader="false" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<a href="Default7.aspx?topicid=<%# DataBinder.Eval(Container.DataItem,"topicid")%>" target ="_blank" >
<%#DataBinder.Eval(Container.DataItem, "topic")%> </a>
(<%# DataBinder.Eval(Container.DataItem,"postby")%>)
(<%# DataBinder.Eval(Container.DataItem,"answer")%>)
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:Gridview>
</form>
</body>
</html>