如何从列表框中删除项目? [英] How to remove an item from a listbox?

查看:174
本文介绍了如何从列表框中删除项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从列表框中删除和计时,但我收到此错误

I am trying to remove and time from a listbox but I am getting this error

Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> 





我试过



I have tried

enableEventValidation="false"

但页面无效它的方式。



ListBox将从Gridview中填充。但我认为每次点击页面上的按钮时,列表都会更新







感谢你的回复。



我尝试过的事情:



but the page is not working the way it should.

The ListBox is getting populated from a Gridview. But I think the list gets

updated everytime I click a button on the page.

thanks for you response.

What I have tried:

int a = LBDuties.SelectedIndex;
                LBDuties.Items.RemoveAt(a);
               // LBDuties.Items.Remove(LBDuties.SelectedValue);
              //  LBDuties.SelectedIndex = 1;

推荐答案

更多细节将有助于更好地理解问题。根据您的解释,不清楚异常发生的时间和地点(代码部分)。如果要阻止特定控件的回发(不需要回发),请将AutoPostBack属性设置为false。
More details would help to understand the problem better. From your explanation it is not clear when and where (code part) the exception is occurring. If you want to prevent postback for a specific control, where postback is not necessary, set AutoPostBack property to 'false'.


List<string> temp = new List<string>();

    foreach (string item in listBox1.Items)
    {
        string removelistitem = "RemoveValue";
        if(item.Contains(removelistitem))
        {
            ArraySample.Items.Add(item);
         }
     }

    foreach(string item in ArraySample)
    {
       listBox1.Items.Remove(item);
    }


这篇关于如何从列表框中删除项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆