学习VS2005杂记
aspx代码:
<div>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<div><a href="#"><%# Eval("loginfo")%></a></div><br />
</ItemTemplate>
</asp:Repeater>
</div>
cs代码:
using System.Data.SqlClient;
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Server=(local);DataBase=Codematic;User ID=sa;Password=";
string strSql = "SELECT * FROM S_LOG";
SqlCommand cmd = new SqlCommand(strSql);
cmd.CommandText = strSql;
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
cmd.Connection = conn;
da.SelectCommand = cmd;
conn.Open();
da.Fill(ds);
conn.Close();
this.Repeater1.DataSource = ds.Tables[0].DefaultView;
this.Repeater1.DataBind();
与2003的不同之处是控件绑定的格式更加简化了:
<%# Eval("loginfo")%>
VS2003的格式:
<asp:TemplateColumn HeaderText="电话">
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" Width="13%"></ItemStyle>
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "TEL") %>
</ItemTemplate>
</asp:TemplateColumn>