如何使用c#验证asp.net中列表框中的重复值 [英] how to validate the duplicate value in listbox in asp.net using c#

查看:87
本文介绍了如何使用c#验证asp.net中列表框中的重复值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

学生ID textbox1 1000按钮(添加)



当我点击该按钮1000时,它将被添加到列表框中。



列表框如下

1000.



然后再次点击添加按钮1000无法添加到listbox。



我怎样才能在asp.net中使用c#验证。



问候,

Narasiman P.

student id textbox1 1000 Button (Add)

when i click that button 1000 it will be added in the listbox.

listbox as follows
1000.

Then again when i click the add Button 1000 cannot be added in the listbox.

for that how can i validate in asp.net using c#.

Regards,
Narasiman P.

推荐答案

你好,

试试这种方式..

Hello ,
Try this way..
 if(!listBox1.Items.Contains(textvalue)) 
{
  //Add data to listbox
}



谢谢


thanks


试试这个.. :)



try this.. :)

if (!ListBox1.Items.Contains(ListBox1.Items.FindByText(item)))
{    
    ListBox1.Items.Add(item);
}
else
{
  Response.Write(@"<SCRIPT LANGUAGE=""JavaScript"">alert('Duplicate value hadbeen entered')</SCRIPT>");
}





参考.. :)



< a href =http://stackoverflow.com/questions/20218244/check-for-duplicate-values-in-listbox-and-give-error-message>检查列表框中的重复值并提供错误消息 [ ^ ]



检查重复项的列表框并删除重复项? [ ^ ]


如果您将列表框绑定到集合,则可以在集合中搜索以检查此新数据是否已存在。

如果没有集合,只需通过listview并检查此数据是否存在。
If you are binding the listbox to a collection, you can search in the collection to check if this new data exists already.
If there is no collection, simply fileter through the listview and check if this data exists.


这篇关于如何使用c#验证asp.net中列表框中的重复值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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