开发者

How to clear an ASP.NET datagrid?

开发者 https://www.devze.com 2023-01-26 00:34 出处:网络
how do i clear the contents of a data grid that\'s bound to an list of generic objects? private void BindGrid(ReportWizardCriteria criteria)

how do i clear the contents of a data grid that's bound to an list of generic objects?

private void BindGrid(ReportWizardCriteria criteria)
{

    gvCriteria.DataSour开发者_StackOverflow社区ce = criteria.CriteriaList;
    gvCriteria.DataBind();
}


gvCriteria.DataSource = null;
gvCriteria.DataBind();

Or you can bind it to an empty collection as well, similar to this

gvCriteria.DataSource = new List<MyObject>();
gvCriteria.DataBind();

For some people the second one is a bit "easier" to understand


You can set the .DataSource property to null. That ought to do it.

gvCriteria.DataSource = null;
gvCriteria.DataBind();


try,

gvCriteria.Items.Clear();

or,

gvCriteria.DataSource = null;

gvCriteria.DataBind();

0

精彩评论

暂无评论...
验证码 换一张
取 消