label控件问题
我用的是vb语言vs2008开发
我给所有带图片的新闻都做了一个istu的标识符,如果istu=1那么新闻列表就应该显示image_s.gif这个图。我是这样写的
- VB.NET code
Private Sub Rep1_ItemDataBound1(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles Rep1.ItemDataBound Dim lab As Label = CType(e.Item.FindControl("Label2"), Label) Dim sql As String Dim dv As DataView sql = "select * from news where istu=1 and news_type='02.03'" dv = oradb.sqldb.filldata(sql) If dv.Count > 0 Then lab.Text = "<img src='images/image_s.gif' border='0'>" End IfEnd Sub可是总是出现
- HTML code
未将对象引用设置到对象实例lab.Text = "<img src='images/image_s.gif' border='0'>"
这个问题可能满白的,但我真的解决不了了,急求答案!
[解决办法]
Dim lab As Label = CType(e.Item.FindControl("Label2"), Label)
这一句后面当然要判断转换是否成功,如果每找到,需要判断lab.
加这样一句
If lab is nothing then Exit Sub