这几天自己在写东西的时候 发现 数据绑定控件的应用很多 于是自己想总结一下 总结才有提高吗 不说废话啦 开始吧 首先 谈谈repeater 的用法 (目前用的不多,写的不好见谅)using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.Sql; using System.Data.SqlClient; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Bind(); } string connectionstring = "server=.;database=EastTravelGame;Integrated Security=sspi"; public void Bind() { SqlConnection conn = new SqlConnection(connectionstring); try { conn.Open(); //SqlCommand comm = new SqlCommand("select * from Contact", conn); SqlDataAdapter Adapter = new SqlDataAdapter("select * from Contact", conn); DataSet ds = new DataSet(); Adapter.Fill(ds); Repeater1.DataSource = ds.Tables[0].DefaultView; Repeater1.DataBind(); } catch (Exception ex) { throw new Exception(ex.Message); } finally { conn.Close(); } } } <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>无标题页</title> </head> <body> <form id="form1" runat="server"> <div> <asp:Repeater ID="Repeater1" runat="server"> <HeaderTemplate> <table> <tr> <td>ContactID</td> <td>ContactName</td> <td>Descriotion</td> </tr> </table> </HeaderTemplate> <ItemTemplate> <table> <tr> <td><%#DataBinder.Eval(Container.DataItem,"ContactID") %></td> <td><%#DataBinder.Eval(Container.DataItem,"ContactName") %></td> <td><%#DataBinder.Eval(Container.DataItem,"Description") %></td> </tr> </table> </ItemTemplate> </asp:Repeater> </div> </form> </body> </html>