asp.net前台用datalist绑定数据

2024-11-26 16:52:12
推荐回答(3个)
回答1:

string str = "select * from Users ";
SqlCommand cmd = new SqlCommand(str, conn);
DataSet ds = new DataSet();
SqlDataAdapter das = new SqlDataAdapter();
das.SelectCommand = cmd;
das.Fill(ds);
DataTable dt = new DataTable();
dt = ds.Tables[0];
DataView dv = ds.Tables[0].DefaultView;
dv.RowFilter = "UserID>0and UserID<2";
DataList1.DataSource = dv;
DataList1.DataBind();
格式就是这样。。。dv.RowFilter = "UserID>0and UserID<2";
这个是判断你那个字段UserID的显示范围,你稍修改下就OK了。。

回答2:

DataView dv = ds.Tables[0].DefaultView;
dv.RowFilter = "ID>3 and ID<10";
this.rep_new.DataSource = dv;
this.rep_new.DataBind();

回答3:

DataView dv = ds.Tables[0].DefaultView;
dv.RowFilter = "ID>3 and ID<10";