Questions tagged «object-type»

2
如何检查对象是否为特定类型
我将各种对象传递给子例程以运行相同的过程,但每次都使用不同的对象。例如,在一种情况下,我正在使用ListView,而在另一种情况下,我正在传递DropDownList。 我想检查传递的对象是否为DropDownList,然后执行某些代码(如果是)。我该怎么做呢? 到目前为止,我的代码不起作用: Sub FillCategories(ByVal Obj As Object) Dim cmd As New SqlCommand("sp_Resources_Categories", Conn) cmd.CommandType = CommandType.StoredProcedure Obj.DataSource = cmd.ExecuteReader If Obj Is System.Web.UI.WebControls.DropDownList Then End If Obj.DataBind() End Sub
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.