1.向页面中添加ListView控件,然后在下方添加一个ObjectDataSource
2.配置数据源:根据需要,选择相应的方法体,当定义参数时,将其设为空格
3.在ListView控件中选择数据源(即为前面已经添加好的数据源),然后配置ListView,选项中根据需要选择(这里为全部选择)。
这样就完成了一个界面。
如何用ListView实现真正的分页呢
1.向页面中拖入3个 控件:ListView,DataPager,ObjectDataSource
2.在DataPager中选择分页的样式
3.在ObjectDataSource的属性窗口中将EnablePaging属性设置为true,这里要注意MaximumRowsParameterName和StartRowIndexParamerName属性;
SelectCountMethod属性设置为GetNewsCount
4.根据需要,添加相应的方法:
public List<Model.HKSJ_Main> LoadPageUser4ListView(int maximumRows, int startRowIndex)
{
int total=0;
//返回当前页的数据
return this.LoadPageMainByProc(maximumRows, Math.Max((startRowIndex + maximumRows+1) / maximumRows, 1), out total);
}
public int GetNewsCount()
{
return this.GetRecordCount(string.Empty);
}
5.如上面一样 将ListView配置数据源,这里选项中不要选择分页;
即可实现!