GridView在回发时显示双倍

时间:2010-08-11 07:45:33

标签: c# asp.net gridview

我有一个应该使用

刷新的gridview
        gridView.DataSource = null;
        gridView.DataBind();

在将其绑定到更新的数据源(这是一个DataTable)之前。

然后

gridView.DataSource = newDataTable;
gridView.DataBind();

问题是它不会清除,并且我不时会在另一个表的顶部找到一个表(顶部的表是更新的表,底部的表是第二个DataBind之前的数据)。

感谢您的帮助!

2 个答案:

答案 0 :(得分:0)

我通常会连接数据源更新或插入的事件,然后在执行插入和更新后直接调用DataBind方法。

您也可以尝试在重新加载网格之前添加它,尽管数据绑定应该刷新它:

gridView.Dispose();

答案 1 :(得分:0)

        gv_BCDashboard.Columns.Clear(); -- Clearing the Columns and rebinding.
        foreach (DataColumn col in bcDashboard.Columns)
        {
            //Declare the bound field and allocate memory for the bound field.
            BoundField bfield = new BoundField();

            //Initalize the DataField value.
            bfield.DataField = col.ColumnName;

            //Initialize the HeaderText field value.
            bfield.HeaderText = col.ColumnName;

            //Add the newly created bound field to the GridView.
            gv_BCDashboard.Columns.Add(bfield);
        }
                    
        gv_BCDashboard.DataSource = bcDashboard;
        gv_BCDashboard.DataBind();

    }
相关问题