怎么从数据库读取一系列商品信息并在前台展示
如何从数据库读取一系列商品信息并在前台展示。
前台后台该如何写,新手请教。
------解决方案--------------------
一般在后台都需要有对应的DataBind()在执行绑定。
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindDataList();
}
}
private void BindDataList()
{
string con="";
string strSql = "SELECT * FROM table";//定义一条SQL语句
SqlDataAdapter sda = new SqlDataAdapter(strSql, con);
DataSet ds = new DataSet();
sda.Fill(ds);
newproductlist.DataSource = ds;
newproductlist.DataBind();
}
前台后台该如何写,新手请教。
------解决方案--------------------
一般在后台都需要有对应的DataBind()在执行绑定。
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindDataList();
}
}
private void BindDataList()
{
string con="";
string strSql = "SELECT * FROM table";//定义一条SQL语句
SqlDataAdapter sda = new SqlDataAdapter(strSql, con);
DataSet ds = new DataSet();
sda.Fill(ds);
newproductlist.DataSource = ds;
newproductlist.DataBind();
}