无法从后面的代码访问html列表框控件. [英] Cannot access html listbox control from code behind.

查看:84
本文介绍了无法从后面的代码访问html列表框控件.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我有一个由xml解析填充的html列表框.但是,当我尝试获取此html列表框的选定项目时,我无法在其中获取任何itmes,我总是将其计数为null.
我试过了

Hello guys,
I have a html listbox which i have populated by xml parsing. But when i am trying to get the selected items of this html listbox, i am unable to get any itmes in it, i always get its count as null.
I tried this

Control drpSkills_ctrl = (ListBox)FindControl("ctl00$ContentPlaceHolder1$drpSkills");



使用上面的代码,我可以在rpSkills_ctrl中获得列表框,但是我没有获得.items.count属性.

任何人都可以帮助我如何获取列表框并对其项目执行foreach或for循环



With the above code i am able to get the listbox in rpSkills_ctrl but i dont get .items.count property.

Can anyone help how can i get the listbox and do foreach or for loop on its items

推荐答案

ContentPlaceHolder1
ContentPlaceHolder1


drpSkills");
drpSkills");



使用上面的代码,我可以在rpSkills_ctrl中获得列表框,但是我没有获得.items.count属性.

任何人都可以帮助我如何获取列表框并对其列表项进行foreach或for循环



With the above code i am able to get the listbox in rpSkills_ctrl but i dont get .items.count property.

Can anyone help how can i get the listbox and do foreach or for loop on its items


您不能直接访问该控件吗?即使是这样的服务器端HTML控件:

Can''t you access the control directly? Even if it''s a server side Html control like this:

<select runat="server" id="drpSkills">
//options
</select>



您仍然应该可以像这样直接访问它:



You should still be able to access it directly like this:

Control drpSkills_ctrl = drpSkills;



或如果问题是找到了控件但无法访问它的项目集合,则需要将其强制转换为正确的类型,该类型应为HtmlSelect:

http://msdn.microsoft.com/en-us/library/807bc327.aspx [ ^ ]



or if the problem is that you''ve found the control, but you can''t access it''s items collection, you''ll need to cast it to the correct type which should be HtmlSelect:

http://msdn.microsoft.com/en-us/library/807bc327.aspx[^]


这篇关于无法从后面的代码访问html列表框控件.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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