遍历列表框 [英] Loop throught Listbox

查看:86
本文介绍了遍历列表框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何遍历列表框

我使用此代码,但无法正常工作.
有什么主意吗?

How to loop throught Listbox

I use this code, but its not working.
Any idea?

For Each item As String In lstmnth.SelectedItem.Value
       MessageBox.Show(item.ToString())
Next

推荐答案

首先,您应该遍历lstmnth.Items而不是lstmnth.SelectedItem.Value,因为它只有一个值.

其次,MessageBox不能在ASP.NET中使用,它不能作为Windows Form东西使用.
First of all, you should be looping through lstmnth.Items and not lstmnth.SelectedItem.Value as it has only one value.

Second, MessageBox does not work in ASP.NET, its as Windows Form thingie.


好吧,这是适合您的C#代码段.希望您可以将其转换为VB.NET

Well, here is C# Snippet for you. Hope you can convert it into VB.NET

foreach (ListItem s in listControl.Items)
     {
         Response.Write(s.Value);
     }


希望对您有所帮助!


Hope this will help you !


感谢重播

问题已解决

Thanks For replay

problem is solved

For i As Integer = 0 To lstmnth.Items.Count - 1
           If lstmnth.Items(i).Selected Then
              MessageBox.Show(lstmnth.Items(i).Value.ToString())
           End If
Next


这篇关于遍历列表框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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