关于GridView分页的疑惑
[code=C#][/code]
前台页面Gridview的数据源为ObjectDataSource控件的数据:
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetData"
TypeName="ZWW.BLL.VideoDataSource" MaximumRowsParameterName="pageSize" StartRowIndexParameterName="startIndex"
EnablePaging="True" SelectCountMethod="GetTotal" DeleteMethod="DeleteVideo">
<SelectParameters>
<asp:ControlParameter ControlID="ddl_courseId" Name="COURSE_ID" PropertyName="Text" />
<asp:ControlParameter ControlID="tb_videoname" Name="VideoName" Type="String"/>
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="VIDEO_ID" Type="Int64" />
</DeleteParameters>
</asp:ObjectDataSource>
分页方法的实现:
[DataObject]
public class VideoDataSource
{
[DataObjectMethod(DataObjectMethodType.Select, true)]
public IEnumerable GetData(int startIndex, int pageSize, string VideoName, long COURSE_ID)
{
DataClassesDataContext db = DataClassesDataContext.Default;
IQueryable<T_VIDEO> videos = db.T_VIDEO;
if (!string.IsNullOrEmpty(VideoName))
{
VideoName = VideoName.Trim();
videos = videos.Where(u => u.VIDEO_NAME.Contains(VideoName));
}
if (COURSE_ID != 0)
{
videos = videos.Where(v => v.COURSE_ID == COURSE_ID);
}
var data = videos.Select(v => new
{
v.VIDEO_ID,
v.VIDEO_NAME,
v.VIDEO_URL,
v.ORDER_ID,
v.TIME_LENGTH,
v.VIDEO_DESC,
v.T_COURSE.COURSE_NAME
}
).OrderBy(v => v.ORDER_ID).Skip(startIndex).Take(pageSize).ToArray();
return data;
}
public int GetTotal(string VideoName, long COURSE_ID)
{
DataClassesDataContext db = DataClassesDataContext.Default;
IQueryable<T_VIDEO> videos = db.T_VIDEO;
if (!string.IsNullOrEmpty(VideoName))
{
VideoName = VideoName.Trim();
videos = videos.Where(u => u.VIDEO_NAME.Contains(VideoName));
}
if (COURSE_ID != 0)
{
videos = videos.Where(v => v.COURSE_ID == COURSE_ID);
}
return videos.Count();
}
我很疑惑的就是[DataObject]和[DataObjectMethod(DataObjectMethodType.Select, true)]的作用。
另外public IEnumerable GetData方法的返回类型如果改为IQueryable也是有问题的,这是为什么???求帮帮忙,小弟是新手
------解决方案--------------------
DataObject :将某一类型标识为适合绑定到 ObjectDataSource 对象的对象
DataObjectMethod :标识由某一类型公开的数据操作方法,该方法所执行的操作类型以及该方法是否是默认的数据方法
具体的你看帮助