コード例 #1
0
        public void BindGridView(string location)
        {
            AdvertiseService service = new AdvertiseService();

            AdvertiseDspModel[] mylist = service.GetObjectsByLocation(location);
            DataSet             ds     = new DataSet("ds_advertise");
            DataTable           dt     = new DataTable("ds_advertise");

            dt.Columns.Add(new DataColumn("Id", typeof(string)));
            dt.Columns.Add(new DataColumn("Name", typeof(string)));//为dt_dry表内建立Column
            dt.Columns.Add(new DataColumn("Begin", typeof(string)));
            dt.Columns.Add(new DataColumn("End", typeof(string)));
            for (int i = 0; i < mylist.Length; i++)
            {
                DataRow dr = dt.NewRow();
                dr["Id"]    = mylist[i].ID;
                dr["Begin"] = mylist[i].BeginTime.ToString("yyyy-MM-dd");
                dr["End"]   = mylist[i].EndTime.ToString("yyyy-MM-dd");

                dr["Name"] = mylist[i].AdvertiseName;
                dt.Rows.Add(dr);
            }
            ds.Tables.Add(dt);
            AdvertiseGridView.DataSource = ds.Tables[0].DefaultView;
            AdvertiseGridView.DataBind();
        }