[英]Unable get Label.text in ASP.Net Repeater using FindControl
I can access the text within a textbox within my repeater, but I am unable to pull the text value from a label within my repeater. 我可以在中继器的文本框中访问文本,但是无法从中继器的标签中提取文本值。 The repeater is populated from a datatable with row(x) being filled by sqlreader(x), I don't know if that makes a difference.
从数据表中填充转发器,并用sqlreader(x)填充row(x),我不知道这是否有所不同。 I cannot use javascript for this.
我不能为此使用javascript。 I need to access the label value from the codebehind.
我需要从后面的代码访问标签值。
<asp:label id="weiLabel" runat="server">
<%#DataBinder.Eval(Container, "DataItem.weiLabel")%>
</asp:label>
is the markup 是标记
I can access a textbox on the same row using: 我可以使用以下命令访问同一行上的文本框:
featTable.Controls(1).Controls(1).FindControl("costText")
and retrieve the textbox.text, but using the same statement for the label gives me {text=""}. 并检索textbox.text,但是对标签使用相同的语句会给我{text =“”}。
I have verified that the clientID of control that is returned with findcontrol is correct (featTable__ctl1_weiLabel) 我已经验证了用findcontrol返回的控件的clientID是正确的(featTable__ctl1_weiLabel)
Thanks for any help 谢谢你的帮助
您可以尝试这样声明您的标签吗:
<asp:label id="weiLabel" runat="server" Text='<%#DataBinder.Eval(Container, "DataItem.weiLabel")%>' / >
You can also try putting in the value into your label from the code behind using the databound method. 您也可以尝试使用databound方法从后面的代码中将值放入标签中。 I find it a bit easier to debug and cleaner then putting it in the html
我发现它更容易调试和清除,然后将其放入html
Private Sub repPoliList_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles repPoliList.ItemDataBound
If (e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem) Then
Dim dr As DataRowView = CType(e.Row.DataItem, DataRowView)
Dim weiLabel As System.Web.UI.WebControls.Label= CType(e.Item.FindControl("weiLabel"), System.Web.UI.WebControls.Label)
weiLabel.text= dr("ColumnFromDatabase").toString
End If
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.