我得到以下错误 - 'OfType'不是'System.Web.UI.ControlCollection'的成员 [英] Im get the following Error - 'OfType' is not a member of 'System.Web.UI.ControlCollection'

查看:72
本文介绍了我得到以下错误 - 'OfType'不是'System.Web.UI.ControlCollection'的成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到以下错误 - ; OfType;不是System.Web.UI.ControlCollection的成员'



这是给出错误的代码



Im get the following Error -;OfType; is not a member of System.Web.UI.ControlCollection'

This is the code thats gives the error

Protected Sub dgdWebsite_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles dgdWebsite.RowDataBound
        Try
            If e.Row.RowType = DataControlRowType.DataRow Then
                Dim item As String = e.Row.Cells(0).Text
                For Each button As Button In e.Row.Cells(7).Controls.OfType(Of Button)()
                    If button.CommandName = "Delete" Then
                        button.Attributes("onclick") = "if(!confirm('Do you want to delete " + item + "?')){ return false; };"
                    End If
                Next
            End If
        Catch ex As Exception
            ShowErrorMsg(ex.Message)
        End Try

    End Sub

推荐答案

如果用代码编写的一些乱码会导致编译错误,那就没什么了不起的。应用于控件集合的 OfType 方法是您幻想的结晶。没有这样的事情,正如你的编译器清楚报道的那样。



如果你想基于它们的运行时类型动态地整理出一些对象,有两个VB.NET运算符, TryCast ;它们的使用应该在MSDN帮助页面中显而易见:

http:// msdn .microsoft.com / zh-cn / library / kb136x1y.aspx [ ^ ],

http:/ /msdn.microsoft.com/en-us/library/zyy863x8.aspx [ ^ ]。



对于 OfType ,有一个通用方法 System.Linq.Enumerable .OfType<>

http://msdn.microsoft.com/en-us/library/vstudio/bb360913%28v=vs.100%29.aspx [ ^ ]。



如果您有实现它的.NET版本(请参阅问题的评论,感谢Kornfeld Eliyahu Peter),您可以将此方法与您的集合一起使用 System.IEnumerable



这些CodeProject文章可能很有用:

.NET中的扩展方法 [ ^ ],

VB.NET中的扩展方法 [ ^ ]。



但最终,在这种方法中实现过滤时,您仍然需要使用 Is 运算符。 :-)



-SA
There is nothing wonderful if some gibberish written in code cause some compilation error. The method OfType applied to a collection of control is a fruit of your fantasy. There is no such thing, as clearly reported by your compiler.

If you wanted to dynamically sort out some objects based on their runtime types, there are two VB.NET operators, Is and TryCast; their use should be obvious from the MSDN help pages:
http://msdn.microsoft.com/en-us/library/kb136x1y.aspx[^],
http://msdn.microsoft.com/en-us/library/zyy863x8.aspx[^].

As to your OfType, there is a generic method System.Linq.Enumerable.OfType<>:
http://msdn.microsoft.com/en-us/library/vstudio/bb360913%28v=vs.100%29.aspx[^].

If you have the version of .NET where it is implemented (please see the comment to the question, thanks to Kornfeld Eliyahu Peter), you can use this method with your collection to System.IEnumerable.

These CodeProject articles could be useful:
Extension Methods in .NET[^],
Extension Methods in VB.NET[^].

But ultimately, in the implementation of the filtering in such a method you would still need to use the Is operator. :-)

—SA


If e.Row.RowState <> DataControlRowState.Edit Then
               If e.Row.RowType = DataControlRowType.DataRow Then
                   Dim id As String = e.Row.Cells(0).Text
                   Dim lb As ImageButton = DirectCast(e.Row.Cells(6).Controls(0), ImageButton)

                   If lb IsNot Nothing Then
                       lb.Attributes("onclick") = "if(!confirm('Do you want to delete " + id + "?')){ return false; };"
                   End If
                   Dim Sel As ImageButton = DirectCast(e.Row.Cells(7).Controls(0), ImageButton)
                   If Sel IsNot Nothing Then
                       Dim path As String = e.Row.Cells(4).Text
                       Sel.Attributes("onclick") = "window.open('" + path + "','_blank');"
                   End If
               End If
           End If


尝试导入库



Imports System.Web.UI.ControlCollection

Imports System.Linq



我试试吧,这是工作。
Try to import library

Imports System.Web.UI.ControlCollection
Imports System.Linq

I try doint it ,It is work.


这篇关于我得到以下错误 - 'OfType'不是'System.Web.UI.ControlCollection'的成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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