.如何将DataView绑定到DataGrid Web控件-----.net学习

  void  Page_Load(Object sender, EventArgs e )  {
        
            
if (!Page.IsPostBack) {
            
                DataTable dt 
= new DataTable();
                DataRow dr;

                dt.Columns.Add(
new DataColumn("列号"typeof(Int32)));
                dt.Columns.Add(
new DataColumn("项目"typeof(string)));
                dt.Columns.Add(
new DataColumn("日期"typeof(DateTime)));
                dt.Columns.Add(
new DataColumn("布尔值"typeof(bool)));

                
for (int i = 1; i <= 9; i++{
                
                    dr 
= dt.NewRow();

                    dr[
0= i;
                    dr[
1= "Item " + i.ToString();
                    dr[
2= DateTime.Now;
                    dr[
3= (i % 2 != 0? true : false;

                    dt.Rows.Add(dr);
                }

           
                dataGrid1.DataSource 
= new DataView(dt);
                dataGrid1.DataBind();
            }

        }

你可能感兴趣的:(datagrid)