2012-12-21 132 views
1

好吧我一直在为此奋战几天,无法在任何地方找到答案。将文字添加到标签控件

我使用的框架3.5和 - // W3C // DTD XHTML 1.0过渡// EN

现在,这里是我的问题:

当我升级的框架我所有的vb.net页面停止加工。我得到'文字'不是'标签'的成员。他们的工作只是找到之前,现在我没有尝试解决这个问题。我通常是一个C#编码器,但只有很多页面进行转换,所以我需要一个解决方案。

这里是我所尝试过的一些样本:

Dim lbl As String = DirectCast(row.FindControl("labelID"), label).Text() 
someLabel.Text = Trim(lbl.Text) 

Dim lbl As label = TryCast(row.FindControl("labelID"), label) 
someLabel.Text = Trim(lbl.Text) 

Dim lbl As label = CType(row.FindControl("labelID"), label) 
someLabel.Text = Trim(lbl.Text) 

每个尝试给了我同样的错误。我是否缺少程序集引用或其他内容? 这里是我使用清单:

Imports System.Data.SqlClient 
Imports System.Data.SqlTypes 
Imports System.Data.Sql 
Imports System 
Imports System.Data 
Imports System.Web.Mail 
Imports System.Web.Configuration 
Imports System.Object 
Imports System.Web.UI.Control 
Imports System.Web.UI.WebControls 
Imports System.Web.UI.WebControls.MultiView 
Imports System.Collections.CollectionBase 

编辑::

好吧,我发现这个问题。我有一个非常老的类,它干扰了App_Code文件夹中的转换。一旦我删除班级,我用它来定义我的标签:

Dim lbl As String = CType(row.FindControl("LabelID"), label).Text 
someLabel.Text = Trim(lbl) 

谢谢你的帮助。

+2

文字属性但你。文本()在第一行.. – Sunny

+0

不过,DirectCast行是因为.Text()而失败的行。 –

回答

0

我使用这个为我正在工作的listwiew。 步长值标签变量,然后把它传递给同一个标签

C#

  LinkButton btn = e.CommandSource as LinkButton; // Identify the link button 
      ListViewItem item = btn.NamingContainer as ListViewItem; 
      Label lbl1 = item.FindControl("Label1") as Label; 
       if (lbl1.Text != "1") 
       { 
        lbl1.Text = "1"; 
       } 

VB

  Dim btn As LinkButton = TryCast(e.CommandSource, LinkButton) 
      ' Identify the link button 
      Dim item As ListViewItem = TryCast(btn.NamingContainer, ListViewItem) 
      Dim lbl1 As Label = TryCast(item.FindControl("Label1"), Label) 
       If lbl1.Text <> "1" Then 
       lbl1.Text = "1" 
       End If