我在我的 asp.net 页面中使用了一个 asp.net 中继器,如下所示:
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<asp:Label ID="lblsSICCode" runat="server" Text='<%# Eval("sSICCode") %>'></asp:Label>
<asp:LinkButton ID="lnkSelect" runat="server" CommandArgument='<%# Eval("sSICCode") %>' OnCommand="LinkButton1_Command" CommandName="MyUpdate">Select</asp:LinkButton>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("sSICCode") %>'></asp:Label>
</ItemTemplate>
</asp:Repeater>
每当单击链接按钮时,我都想更改标签文本。我正在使用以下代码,但它会更改所有中继器的标签。选定行前面的 Label1 应获取 mylabel 的值。
Protected Sub LinkButton1_Command(sender As Object, e As CommandEventArgs)
If e.CommandName = "MyUpdate" Then
For Each RI As RepeaterItem In Repeater1.Items
Dim MyLabel As Label = TryCast(RI.FindControl("lblsSICCode"), Label)
If MyLabel IsNot Nothing Then
If MyLabel.Text = e.CommandArgument Then
Response.Write(e.CommandArgument + "<br />")
End If
End If
Next
End If
End Sub