asp.net 向repeater多加几条数据绑定
3个回答
展开全部
/*第一种,使用ADO.net DataSet连接到GridView*/
//1.创建连接字符串和命令字符串
string connectionString = "Data Source=127.0.0.1;Initial Catalog=Northwind;Integrated Security=True";
string commandString = "Select * From Customers";
//2.为SQLDataAdapter构造函数传递一个字符串
SqlDataAdapter dataAdapter = new SqlDataAdapter(commandString, connectionString);
//3.创建一个DataSet
DataSet dataSet = new DataSet();
//4.填充DataSet对象
dataAdapter.Fill(dataSet,"Customers");
//5.从DataSet中获取DataTable
DataTable dataTable = dataSet.Tables["Customers"];
//6.绑定到Repeater1
Repeater1.DataSource = dataTable;
Repeater1.DataBind();
//1.创建连接字符串和命令字符串
string connectionString = "Data Source=127.0.0.1;Initial Catalog=Northwind;Integrated Security=True";
string commandString = "Select * From Customers";
//2.为SQLDataAdapter构造函数传递一个字符串
SqlDataAdapter dataAdapter = new SqlDataAdapter(commandString, connectionString);
//3.创建一个DataSet
DataSet dataSet = new DataSet();
//4.填充DataSet对象
dataAdapter.Fill(dataSet,"Customers");
//5.从DataSet中获取DataTable
DataTable dataTable = dataSet.Tables["Customers"];
//6.绑定到Repeater1
Repeater1.DataSource = dataTable;
Repeater1.DataBind();
展开全部
//repeater的绑定方法。
private void dataBindToRepeater()
{
DataSet ds = new DataSet();
SqlDataAdapter adapter = new SqlDataAdapter("SQL语句","连接字符串");
adapter.Fill(ds);
this.repeater1.DataSource = ds;
this.repeater1.DataBind();
}
一个repeater只能有绑定一个数据源吧。
private void dataBindToRepeater()
{
DataSet ds = new DataSet();
SqlDataAdapter adapter = new SqlDataAdapter("SQL语句","连接字符串");
adapter.Fill(ds);
this.repeater1.DataSource = ds;
this.repeater1.DataBind();
}
一个repeater只能有绑定一个数据源吧。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询