using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Data;
namespace
KingGridView
{
public
partial
class
_Default : System.Web.UI.Page
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(
!
Page.IsPostBack)
{
this
.GridView1.DataSource
=
GetProducts();
this
.GridView1.DataBind();
}
}
private
ProductCollection GetProducts()
{
ProductCollection _pc
=
new
ProductCollection();
for
(
int
i
=
1
; i
<
100
; i
++
)
{
_pc.Add(
new
Product { id
=
i.ToString(), categoryid
=
i.ToString(), createtime
=
System.DateTime.Now.ToString(),
productid
=
i.ToString(), productname
=
i.ToString(), strdesc
=
i.ToString(), strggxh
=
i.ToString() }
);
}
return
_pc;
}
protected
void
GridView1_PreRender(
object
sender, EventArgs e)
{
this
.GridView1.UseAccessibleHeader
=
true
;
this
.GridView1.HeaderRow.TableSection
=
TableRowSection.TableHeader;
}
}
public
class
ProductCollection : ICollection
<
Product
>
{
List
<
Product
>
_Products;
public
ProductCollection()
{
_Products
=
new
List
<
Product
>
();
}
#region
ICollection<Product> Members
public
void
Add(Product item)
{
_Products.Add(item);
}
public
void
Clear()
{
_Products.Clear();
}
public
bool
Contains(Product item)
{
return
_Products.Contains(item);
}
public
void
CopyTo(Product[] array,
int
arrayIndex)
{
throw
new
NotImplementedException();
}
public
int
Count
{
get
{
return
_Products.Count; }
}
public
bool
IsReadOnly
{
get
{
return
true
; }
}
public
bool
Remove(Product item)
{
return
_Products.Remove(item);
}
#endregion
#region
IEnumerable<Product> Members
public
IEnumerator
<
Product
>
GetEnumerator()
{
return
_Products.GetEnumerator();
}
#endregion
#region
IEnumerable Members
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return
_Products.GetEnumerator();
}
#endregion
}
public
class
Product
{
public
string
id
{
get
;
set
;
}
public
string
productid
{
get
;
set
;
}
public
string
productname
{
get
;
set
;
}
public
string
categoryid
{
get
;
set
;
}
public
string
strggxh
{
get
;
set
;
}
public
string
createtime
{
get
;
set
;
}
public
string
strdesc
{
get
;
set
;
}
}
}