日期:2014-05-18 浏览次数:20975 次
//生成 TemplateField aa = new TemplateField(); Label l1=new Label(); l1.Text="dd"; aa.ItemTemplate.InstantiateIn(l1) 将aa增加给GridView this.GridView1.Columns.Add(aa)
------解决方案--------------------
--下面是转的 /**//// <summary> /// 绑定生成GridView /// </summary> /// <param name="gdv">要绑定的GridView</param> /// <param name="dtblDataSource">GridView的数据源</param> /// <param name="strDataKey">GridView的DataKeyNames</param> public static void GridViewBind(GridView gdv, DataTable dtblDataSource, string strDataKey) ...{ gdv.Columns.Clear(); gdv.AutoGenerateColumns = false; gdv.DataSource = dtblDataSource; gdv.DataKeyNames = new string[] ...{ strDataKey }; for (int i = 0; i < dtblDataSource.Columns.Count; i++) //绑定普通数据列 ...{ BoundField bfColumn = new BoundField(); bfColumn.DataField = dtblDataSource.Columns[i].ColumnName; bfColumn.HeaderText = dtblDataSource.Columns[i].Caption; gdv.Columns.Add(bfColumn); } gdv.Columns[1].Visible = false; CommandField cfModify = new CommandField(); //绑定命令列 cfModify.ButtonType = ButtonType.Button; cfModify.SelectText = "修改"; cfModify.ShowSelectButton = true; gdv.Columns.Add(cfModify); gdv.DataBind(); }
------解决方案--------------------