1. 每次都要先清楚一下列"Columns.Clear()",在绑定数据
.cs
/// <summary>
/// 动态创建gridview
/// </summary>
/// <param name="strFXFF"></param>
private void CreateDynamicListColumn(string strFXFF)
{
DataSet dsList = InputByBatchData.InitCrossTabInfo(strFXFF);
Session["dt_DynamicList"] = dsList.Tables["dtDynamic"];
DataTable dt_DynamicList = dsList.Tables["dtDynamic"];
Session["dtOriginalBig"] = dsList.Tables["dtOriginalBig"];
DataTable dt_OriginalBig = dsList.Tables["dtOriginalBig"];
InputByBatchIndexList.Columns.Clear();
DevExpress.Web.ASPxGridView.GridViewCommandColumn columncheck = new GridViewCommandColumn();
columncheck.Width = Unit.Parse("20px");
columncheck.ShowSelectCheckbox = true;
InputByBatchIndexList.Columns.Add(columncheck);
DevExpress.Web.ASPxGridView.GridViewCommandColumn column = new GridViewCommandColumn();
column.Caption = "修改";
column.Width = Unit.Parse("60px");
column.EditButton.Visible = true;
column.EditButton.Text = "修改";
InputByBatchIndexList.Columns.Add(column);
InputByBatchIndexList.SettingsEditing.PopupEditFormModal = true;
InputByBatchIndexList.SettingsEditing.PopupEditFormWidth = Unit.Parse("600px");
InputByBatchIndexList.SettingsEditing.PopupEditFormAllowResize = true;
foreach (DataColumn dc in dt_DynamicList.Columns)
{
GridViewDataColumn dataColumn1 = new GridViewDataColumn();
dataColumn1.Caption = dc.ColumnName.ToString();
//绑定列的字段
dataColumn1.FieldName = dc.ColumnName.ToString();
//ITemplate temp = new ItemTemplate(i);
//dataColumn1.DataItemTemplate = new ItemTemplate(i);
//dataColumn1.Visible = i;
InputByBatchIndexList.Columns.Add(dataColumn1);
}
}
.aspx
<dxwgv:ASPxGridView ID="InputByBatchIndexList"
ClientInstanceName="InputByBatchIndexList" AutoGenerateColumns="False" runat="server"
KeyFieldName="试样编号" Width="820px"
OnRowUpdating="InputByBatchIndexList_RowUpdating"
onhtmldatacellprepared="InputByBatchIndexList_HtmlDataCellPrepared" OnCustomCallback="InputByBatchIndexList_CustomCallback">
<Settings ShowHorizontalScrollBar="True" />
<SettingsEditing Mode="PopupEditForm" PopupEditFormWidth="400px" />
<SettingsPager PageSize="10">
<Summary AllPagesText="页数: {0} - {1} ({2} 条记录)" Text="第{0}页 共{1}页 (共{2}条记录)" />
</SettingsPager>
</dxwgv:ASPxGridView>