我有一个ASP ListView控件,用于填充SQL Server数据库中的数据,并且它按设计工作。我也有一个ASP Listbox控件,它从ListView控件中填充了ID和Name,它有点工作,就是如果我选择它它按设计显示,但如果我继续从ListView控件中选择相同的行它继续将它添加到列表框中,这不是我想要的,我宁愿只显示一次,无论我从列表视图中选择了多少次。
这就是我所拥有的
protected void distList_SelectedIndexChanging(object sender, ListViewSelectEventArgs e)
{
int rowIndex;
distList.SelectedIndex = e.NewSelectedIndex;
rowIndex = distList.SelectedIndex;
string sapId = distList.DataKeys[rowIndex].Values[0].ToString();
string DistributorName = distList.DataKeys[rowIndex].Values[1].ToString();
string output = sapId + " " + DistributorName;
SAPListBox.Items.Add(output);
}
我一直站着不动,因为我整天都在努力尝试许多事情,但我想我可能只是遗漏了一些东西。
答案 0 :(得分:0)
int rowIndex;
distList.SelectedIndex = e.NewSelectedIndex;
rowIndex = distList.SelectedIndex;
//You might need to change this, to the listbox rather than a listview. Wasn't quite sure which one you wanted.
var txt = rowIndex;
if (!distlist.Items.ContainsKey(txt))
{
string sapId = distList.DataKeys[rowIndex].Values[0].ToString();
string DistributorName = distList.DataKeys[rowIndex].Values[1].ToString();
string output = sapId + " " + DistributorName;
SAPListBox.Items.Add(output);
}
希望如果没有,这会有所帮助。这是我最好的尝试^^