页面
<asp:TemplateColumn HeaderText="CN">
     <ItemTemplate>
<asp:CheckBox id="SelectChk" runat="server" Checked='<%# DataBinder.Eval (Container.DataItem, "flag") %>'></asp:CheckBox>
     </ItemTemplate>
</asp:TemplateColumn>后台的三个函数:
private void Page_Load(object sender, System.EventArgs e)
{
if( !this.IsPostBack )
{
this.ViewState["DataSource"] = createDataSource();
this.SupplierLst.DataSource = (DataTable)this.ViewState["DataSource"];
this.SupplierLst.DataBind();
}
}private DataTable createDataSource()
{
         SupplierLogic supplierLgc = new SupplierLogic();
DataTable supplierList = supplierLgc.getAllInfo();
supplierList.Columns.Add("flag",typeof(bool));
foreach( DataRow myRow in supplierList.Rows )
{
myRow["flag"] = false;
}
return supplierList;
}private void SupplierLst_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
{
         DataTable dataSource =  (DataTable)this.ViewState["DataSource"];
foreach(DataGridItem dg in this.SupplierLst.Items)
{
string id = dg.Cells[0].Text; 
bool checkValue = ((CheckBox)dg.FindControl("SelectChk")).Checked;
if( checkValue == true) 
{
foreach( DataRow myRow in dataSource.Rows )
{
if( myRow["SupplierID"].ToString() == id)
{
myRow["flag"] = true;
}
}
}
else 
{
foreach( DataRow myRow in dataSource.Rows )
{
if( myRow["SupplierID"].ToString() == id)
{
myRow["flag"] = false;
}
}
}
}
this.SupplierLst.CurrentPageIndex = e.NewPageIndex;
this.SupplierLst.DataSource = dataSource;
this.SupplierLst.DataBind();
this.ViewState["DataSource"] = dataSource;
}
}