getpro

个人备份用,不保证一定正确

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

CS

       string connectionString = "server=.\\SQLEXPRESS;database=BookStore;uid=sa;pwd=sa";
string selectStrin = "Select * from Books";
SqlConnection conn = new SqlConnection(connectionString);
SqlCommand command = new SqlCommand(selectStrin, conn);

conn.Open();
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
Response.Write(reader[0].ToString()+": "+ reader["Title"].ToString() + "<br />");
}
reader.Close();


DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(selectStrin, conn);
da.Fill(ds);
DataTable dt = new DataTable();

GridView1.DataSource = ds;
GridView1.DataBind();

DataList1.DataSource = ds;
DataList1.DataBind();

控件

HTML

<asp:DataList ID="DataList1" runat="server">
<ItemTemplate>
<asp:Label ID="Label2" runat="server"
Text
='<%# DataBinder.Eval(Container.DataItem,"Title") %>'></asp:Label>

=&gt;<asp:Label ID="Label4" runat="server" Text='<%# Bind("Title") %>'></asp:Label>

<asp:HyperLink ID="HyperLink1" runat="server"

NavigateUrl
='<%# DataBinder.Eval(Container.DataItem,"id","WebForm1.aspx?id={0}") %>'>HyperLink</asp:HyperLink>
</ItemTemplate>
</asp:DataList>



 

 



posted on 2011-12-31 07:00  getpro  阅读(436)  评论(0编辑  收藏  举报