C#清除ListView中的所有项目 [英] C# Clear all items in ListView
问题描述
我试图清除我的列表视图,但明确的方法不起作用:
myListView.Items.Clear();
这doen't工作。当我把一个断点在该行,该行执行的,但我的列表视图不为空。为什么?
我通过设置它的数据源到数据表填满我的列表视图。
我的解决方案,现在是数据源设置为空数据表。
我只是想知道为什么明确不做把戏?
我用的母版页。在这里,当按钮为pressed内容页面的某些code。
该方法SearchTitle填充的ListView。
相关code:
保护无效我正在寻找()
{
//清除列表框
ListView1.DataSource =新的DataTable();
ListView1.DataBind(); 开关(ddlSearchType.SelectedValue)
{
案Trefwoorden:
SearchKeyword();
打破;
案影片名称:
SearchTitle();
打破;
案Inhoud:
SearchContent();
打破;
}
}
填充ListView的方法
私人无效SearchTitle()
{
//使面板可见
pnlResult.Visible =真;
pnlKeyword.Visible = FALSE; 搜索=新的搜索(txtSearchFor.Text);
ListView1.DataSource = Search.SearchTitle();
ListView1.DataBind();
}
如何
数据源= NULL;
的DataBind();
I try to clear my listview but the clear method doesn't work:
myListView.Items.Clear();
This doen't work. When i put a breakpoint at this line, the line is executed, but my listview isn't empty. How come??
I fill my listview by setting it's datasource to a datatable.
My solution now is to set the datasource to an empty datatable.
I just wonder why clear don't do the trick?
I use a master page. Here some code of a content page when a button is pressed. The method SearchTitle fills the ListView.
Relevant code:
protected void Zoek()
{
// Clear listbox
ListView1.DataSource = new DataTable();
ListView1.DataBind();
switch (ddlSearchType.SelectedValue)
{
case "Trefwoorden":
SearchKeyword();
break;
case "Titel":
SearchTitle();
break;
case "Inhoud":
SearchContent();
break;
}
}
Method that fills the ListView
private void SearchTitle()
{
// Make panel visible
pnlResult.Visible = true;
pnlKeyword.Visible = false;
Search Search = new Search(txtSearchFor.Text);
ListView1.DataSource = Search.SearchTitle();
ListView1.DataBind();
}
How about
DataSource = null;
DataBind();
这篇关于C#清除ListView中的所有项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!