public static string GridView<T>(this HtmlHelper helper, PageList<T> items, string[] columns, GridViewOption option)
this HtmlHelper helper 这个是.net3.0 中的新特性,我们扩展HtmlHelper这个类,使之具有GridView<T>()这个泛型方法
PageList<T> items 则是指定的数据源(上篇提到过的自定义的数据集合),
string[] columns 这个是指定GridView 显示哪几列,和GridViewOption中的header数组有区别,这个是针对数据库字段或者某个实体的属性,而GridViewOption中的是表格的头部不封显示的字样
(2)
if (columns == null)
{
columns = typeof(T).GetProperties().Select(p => p.Name).ToArray<string>();
}
if (option.Headers == null)
{
option.Headers = columns;
}
else
{
if (option.Headers.Length != columns.Length)
{
option.Headers = columns;
}
}
(3)
HtmlTextWriter writer = new HtmlTextWriter(new StringWriter());
writer.RenderBeginTag(HtmlTextWriterTag.Table);
//标题
RenderHeander<T>(helper, writer, columns, option);
//添加数据行
RenderRow<T>(helper, writer, items, columns, option);
//添加分页
RenderPageList<T>(helper, writer, items, columns, option);
return writer.InnerWriter.ToString(); ;
这段就是调用下面的方法,设置数据
更多方法介绍看下篇