更改转发器内的 asp:label 文本
我在中继器中有这个标签
<asp:Label id="lblsub" runat=server text="sdds" />
,我正在尝试更改此标签的文本,这是背后的代码
For Each Item As RepeaterItem In dg.Items
Dim l As New label
l = CType(Item.FindControl("lblsub"), System.Web.UI.WebControls.Label)
l.text="test"
Next
,不幸的是,此代码对我不起作用,文本值不会改变,所以我将非常乐意提供帮助在这里
谢谢
I have this label inside a repeater
<asp:Label id="lblsub" runat=server text="sdds" />
I am trying to change the text of this label,this is the code behind
For Each Item As RepeaterItem In dg.Items
Dim l As New label
l = CType(Item.FindControl("lblsub"), System.Web.UI.WebControls.Label)
l.text="test"
Next
unfortunately this code doesn't work for me ,the text value doesn't change ,so I will be very happy to some help here
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请参阅我在这个问题中的回答。相信它会解决您的问题。
从转发器控件中获取数据绑定值asp.net
编辑
首先,确保您始终在标记中使用引号:
在后面的代码中尝试类似的操作。如果我的 VB 有点生疏,请原谅我:
语法上只有一些小问题。我不知道它们是否导致了您的问题,但最好先解决简单的问题。
See my answer in this question. Believe it will solve your issue.
Getting the databound value from repeater control in asp.net
EDIT
First of all, make sure you always use quotes in your markup:
Try something like this in your code behind. Forgive me if my VB is a little rusty:
There were just a couple little problems with syntax. I don't know if they are causing your issue, but best get the easy stuff out of the way first.
那段代码什么时候运行?
通过在
Page_Load
中执行以下操作,确保之后不会重新绑定中继器:如果每次绑定中继器时都需要执行这段代码,则将代码放入 DataBound 事件中
:我没有带任何编程软件,所以不确定语法
When is that bit of code being ran?
Make sure you are not rebinding the repeater afterwards by doing the following in your
Page_Load
:If you need to do this bit of code every time the repeater is bound, then put your code into the DataBound event:
I haven't got any programming software with me so unsure of the syntax
C# 代码示例(应该在方法或 page_load 内部)
C# code sample (it should be inside method or page_load)