开发者

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. I cannot use javascript for this. 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("costTe开发者_开发知识库xt") 

and retrieve the textbox.text, but using the same statement for the label gives me {text=""}.

I have verified that the clientID of control that is returned with findcontrol is correct (featTable__ctl1_weiLabel)

Thanks for any help


Can you try declaring your label like this:

<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. I find it a bit easier to debug and cleaner then putting it in the 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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜