动态添加gridview编辑功能
生成了个动态的gridview,现在想在每行的最后添加一个编辑功能,现在添加了按钮,也可以触发相应事件,但就是点击编辑没有编辑文本框出现?怎么解决?代码如下:
程序代码:
if (dt != null) { gvshow = new GridView(); gvshow.Width = Unit.Pixel(1200); gvshow.Height = 20; gvshow.AutoGenerateColumns = false; // gvshow.RowEditing+=new GridViewEditEventHandler(gvshow_RowEditing); gvshow.RowCancelingEdit+=new GridViewCancelEditEventHandler(gvshow_RowCancelingEdit); gvshow.RowEditing += new GridViewEditEventHandler(gvshow_RowEditing); gvshow.RowDeleting += new GridViewDeleteEventHandler(gvshow_RowDeleting); gvshow.DataSource = dt; for (int i = 0; i < dt.Columns.Count; i++) { // TemplateColumn tc1 = new TemplateColumn(); //tc1.HeaderTemplate = new GridView(ListItemType.Header, dt.Columns[i].ColumnName.ToString()); //tc1.EditItemTemplate = new GridViewEditEventHandler(gvshow_RowEditing); //tc1.HeaderText = dt.Columns[i].Caption.ToString(); BoundField bc = new BoundField(); bc.DataField = dt.Columns[i].ColumnName.ToString(); bc.HeaderText = dt.Columns[i].Caption.ToString(); gvshow.Columns.Add(bc); } CommandField cf = new CommandField(); cf.ButtonType = ButtonType.Link; cf.ShowEditButton = true; cf.CausesValidation = false; gvshow.Columns.Add(cf); CommandField cf2 = new CommandField(); cf2.ButtonType = ButtonType.Link; cf2.ShowDeleteButton = true; cf2.CausesValidation = false; gvshow.Columns.Add(cf2); gvshow.DataBind(); this.PhDataTable.Controls.Add(gvshow); }