Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 更改转发器内的asp:标签文本_Asp.net_Vb.net_Repeater - Fatal编程技术网

Asp.net 更改转发器内的asp:标签文本

Asp.net 更改转发器内的asp:标签文本,asp.net,vb.net,repeater,Asp.net,Vb.net,Repeater,我把这个标签放在中继器里 <asp:Label id="lblsub" runat=server text="sdds" /> 不幸的是,这段代码不适合我,文本值没有改变,所以我很乐意在这里提供一些帮助 谢谢请看我对这个问题的回答。相信它会解决你的问题 编辑 首先,确保标记中始终使用引号: <asp:Label ID="lblsub" runat="server" Text="sdds" /> 只是语法上有一些小问题。我不知道它们是否导致了您的问题,但最好先解决简单

我把这个标签放在中继器里

<asp:Label id="lblsub" runat=server text="sdds" />
不幸的是,这段代码不适合我,文本值没有改变,所以我很乐意在这里提供一些帮助


谢谢

请看我对这个问题的回答。相信它会解决你的问题

编辑

首先,确保标记中始终使用引号:

<asp:Label ID="lblsub" runat="server" Text="sdds" />

只是语法上有一些小问题。我不知道它们是否导致了您的问题,但最好先解决简单的问题。

这段代码什么时候运行

在加载
页面中执行以下操作,确保之后没有重新绑定中继器:

Sub Page_load
   If not Page.IsPostBack Then
      BindRepeater()
   End If
End Sub
如果每次绑定中继器时都需要执行这段代码,请将代码放入DataBound事件:

Protected Sub dg_ItemDataBound(sender As Object, e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles dg.ItemDataBound
   Select Case e.item.itemtype
       Case ListItemType.Item, ListItemType.AlternatingItem
    Dim l As Label = e.Item.FindControl("lblsub")
    l.Text = "foo"
   End Select
End Sub
我没有带任何编程软件,所以对语法不太确定

C#代码示例(应该在方法或页面加载中)


我不知道我的朋友在你的答案中应该看什么,我没有看到如何更改labelI的文本我也在用你的代码获取null:System.NullReferenceException:Object reference未设置为对象的实例。你打算在什么时候更改文本?能否将代码移动到ItemDataBound事件?这种方法肯定有效,所以肯定还有其他的事情发生。谢谢james,你说得对,这需要在itemdatabound内部发生:Sub R1_itemdatabound(发送方作为对象,e作为RepeaterItemEventArgs)对于dg.Items Dim l作为标签l=directcast(e.Item.FindControl(“lblsub”),标签中的每个项目作为RepeaterItem如果l不是什么,那么l.text=“dsd”end如果Next end sub我不这么认为。顺便说一下,当您在ItemDataBound事件中时,不要使用循环。只需使用e.Item.FindControl(“lblsub”)我尝试了您的代码,但得到了null:System.NullReferenceException:Object reference未设置为对象的实例。我已对代码进行了更改,使其不包含页眉/页脚,我认为这是导致null reference异常的原因
Sub Page_load
   If not Page.IsPostBack Then
      BindRepeater()
   End If
End Sub
Protected Sub dg_ItemDataBound(sender As Object, e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles dg.ItemDataBound
   Select Case e.item.itemtype
       Case ListItemType.Item, ListItemType.AlternatingItem
    Dim l As Label = e.Item.FindControl("lblsub")
    l.Text = "foo"
   End Select
End Sub
foreach (RepeaterItem rt in MyRepeater.Items)
            {
                Label l = ((Label)rt.FindControl("lblPrice"));
                l.Text = "200";
            }