WEB.config: <connectionStrings> <add name="conn" connectionString="Data Source=orcl;User ID=qxw;Password=123456" providerName="System.Data.OracleClient"/> </connectionStrings> 数据库类:DBTool.cs: public class DBTool { public OracleConnection GetConnection() { string str = ConfigurationManager.ConnectionStrings["conn"].ConnectionString; OracleConnection conn = new OracleConnection(str); return conn; } public DataTable Get_FFLOWList() { string sql = "select * from rr"; OracleConnection conn = GetConnection(); OracleDataAdapter oda = new OracleDataAdapter(sql, conn); DataTable dt = new DataTable(); oda.Fill(dt); return dt; } } 载入页面: protected void Page_Load(object sender, EventArgs e) { DBTool tool = new DBTool(); DataTable dt = tool.Get_FFLOWList(); GridView1.DataSource = dt; GridView1.DataBind(); DataList1.DataSource = dt; DataList1.DataBind(); Repeater1.DataSource = dt; Repeater1.DataBind(); } ASPX: GridView: <asp:GridView ID="GridView1" runat="server" BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px" CellPadding="2" EnableModelValidation="True" ForeColor="Black" GridLines="None"> <AlternatingRowStyle BackColor="PaleGoldenrod" /> <FooterStyle BackColor="Tan" /> <HeaderStyle BackColor="Tan" Font-Bold="True" /> <PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" /> <SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" /> </asp:GridView> DataList: <asp:DataList ID="DataList1" runat="server" CellPadding="4" ForeColor="#333333"> <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" /> <HeaderTemplate> <table border="1"> <tr><td>序号</td><td>名字</td></tr> </HeaderTemplate> <ItemStyle BackColor="#FFFBD6" ForeColor="#333333" /> <ItemTemplate> <tr><td><%# DataBinder.Eval(Container.DataItem, "ID")%></td><td><%# DataBinder.Eval(Container.DataItem, "NAME")%></td></tr> </ItemTemplate> <AlternatingItemStyle BackColor="White" /> <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" /> <FooterTemplate> </table> </FooterTemplate> <SelectedItemStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" /> </asp:DataList> Repeater: <asp:Repeater ID="Repeater1" runat="server" onitemcommand="Repeater1_ItemCommand"> <HeaderTemplate> <table border="1"><tr><td>IDD</td><td>NameE</td></tr> </HeaderTemplate> <ItemTemplate><tr><td><%# DataBinder.Eval(Container.DataItem, "ID")%></td><td><%# DataBinder.Eval(Container.DataItem, "NAME")%></td></tr></ItemTemplate> <AlternatingItemTemplate><tr style="background-color:gray;"><td><%# DataBinder.Eval(Container.DataItem, "ID")%></td><td><%# DataBinder.Eval(Container.DataItem, "NAME")%></td></tr></AlternatingItemTemplate> <FooterTemplate></table></FooterTemplate> </asp:Repeater>