webform1.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="test9_2.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
<HeaderTemplate>
<table border="1">
<tr>
<td><strong>新闻编号</strong></td>
<td><strong>新闻标题</strong></td>
<td><strong>新闻类别</strong></td>
<td><strong>发布时间</strong></td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%#DataBinder.Eval(Container.DataItem,"ID") %></td>
<td><%#DataBinder.Eval(Container.DataItem,"Title") %></td>
<td><%#DataBinder.Eval(Container.DataItem,"Categories") %></td>
<td><%#DataBinder.Eval(Container.DataItem,"IssueDate") %></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:db_newsConnectionString %>" SelectCommand="SELECT * FROM [tb_news]"></asp:SqlDataSource>
</div>
</form>
</body>
</html>
sql
CREATE DATABASE db_news
USE db_news
GO
CREATE TABLE dbo.tb_news(
id int identity(1,1) not null primary key,
title varchar(50) not null,
content varchar(2000) not null,
categories varchar(50) not null,
type1 varchar(50) not null,
issueDate datetime not null default getdate())
GO
insert into tb_news(title,content,categories,type1)
values('创业板开板','新浪财经讯10月17日上午消息 中国证监会主席在企业投融资论坛上透露,经国务院批准成立创业板。','环球经济','国内新闻');
web.config
<?xml version="1.0" encoding="utf-8"?>
<!--
有关如何配置 ASP.NET 应用程序的详细信息,请访问
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<connectionStrings>
<add name="db_newsConnectionString" connectionString="Data Source=LAPTOP-AQKEN65V\SQLEXPRESS08;Initial Catalog=db_news;Persist Security Info=True;User ID=sa;Password=123456"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
</configuration>