各位斑竹,大虾,sumanden、icyer、hgknight……都来看看,从去年到今年都没解决的问题(关于操作动态DataGrid绑定列,在线等待!!!)
页面上有个ListDataGrid,静态绑定了一列。
private void Page_Load(object sender, System.EventArgs e)
{
if ( ! this.IsPostBack )
{
this.Bind();
}
}
public void CreateGrid()
{
BoundColumn BoundCol = new BoundColumn();
BoundCol.HeaderText = "hello";
BoundCol.DataField = "xxx";
BoundCol.SortExpression = "xxx";
ListDataGrid.Columns.Add( BoundCol );
}
private void ListDataGrid_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
{
this.Bind();
conn.dv.Sort = e.SortExpression;
ListDataGrid.DataBind();
}
private void Bind()
{
CreateGrid();
StringBuilder ListSql = new StringBuilder();
ListSql.Append( " SELECT * FROM Table1 ");
if ( conn.GetRowCount( ListSql.ToString() ) > 0 )
{
ListDataGrid.DataSource = conn.CreateDataSource( ListSql.ToString() );
ListDataGrid.DataBind();
}
}
第一次打开都是好的,但是一点排序,叶面上就只剩下了静态绑定的那列了。相同的代码在纯静态绑定的DataGrid里面一点问题也没有。