• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
我要飞的更高!
一步一个脚印!
博客园    首页    新随笔    联系   管理    订阅  订阅

学习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>

posted @ 2008-02-25 17:46  "鸟巢"  阅读(163)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3