1

我有一个带有项目模板的中继器控件,如下所示:

 <ItemTemplate>
                    <table width="70%">
                        <tr id="rowSIC" runat="server">
                            <td width="10%">
                                <asp:Label ID="lblsSICCode" runat="server" Text='<%# Eval("SICCode") %>'></asp:Label>
                            </td>
                            <td width="70%">
                                <asp:Label ID="Label2" runat="server" Text='<%# Eval("IndustryName") %>'></asp:Label>
                            </td>
                            <td width="10%">
                                <asp:LinkButton ID="lnkSelect" runat="server" CommandArgument='<%# Eval("SICCode") %>'
                                    CommandName="MyUpdate">Select</asp:LinkButton>
                            </td>
                            <td width="10%">
                                <asp:Label ID="Label1" runat="server"></asp:Label>
                            </td>
                        </tr>
                    </table>
                </ItemTemplate>

和 itemCommand 事件,我正在更改转发器行颜色并将其 id 保存在 viewstate 中,如下所示:

Protected Sub Repeater1_ItemCommand(source As Object, e As System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles Repeater1.ItemCommand
        If e.CommandName.Equals("MyUpdate") Then
            Dim MyLabel As Label = TryCast(e.Item.FindControl("lblsSICCode"), Label)
            Dim Label1 As Label = TryCast(e.Item.FindControl("Label1"), Label)
            Dim rowSIC As HtmlTableRow = TryCast(e.Item.FindControl("rowSIC"), HtmlTableRow)

            If MyLabel IsNot Nothing Then
                ' Label1.Text = MyLabel.Text
                rowSIC.BgColor = "#FFDAB9"
                ViewState.Add("selectedItem", MyLabel.Text)
            End If
        End If
    End Sub

我在此页面上有一个树视图,其中每个节点都有 Id 和值。在选定节点更改事件上,我想更改中继器选定节点的文本。我正在编写这样的代码:

Protected Sub TreeView1_SelectedNodeChanged(sender As Object, e As System.EventArgs) 处理 TreeView1.SelectedNodeChanged

    Dim EmployeeRepeater As Repeater = CType(Me.Form.Controls(1).FindControl("Repeater1"), Repeater)
    Dim EmployeeRepeaterItem As RepeaterItem
    Dim EmployeeName As Label

    For Each EmployeeRepeaterItem In Repeater1.Items

        Dim MyLabel As Label = TryCast(EmployeeRepeaterItem.FindControl("lblsSICCode"), Label)
        EmployeeName = CType(EmployeeRepeaterItem.FindControl("Label1"), Label)

        If ViewState("selectedItem") = TreeView1.SelectedValue Then
            EmployeeName.Text = TreeView1.SelectedNode.Text
        End If


    Next

End Sub

但它不是 chagging MyLabel 文本。如何解决?

树视图和转发器都填充在 !Page.Ispostback 事件中

问候, 阿西夫·哈米德

4

1 回答 1

0

在方法中,

TreeView1_SelectedNodeChanged(发送者作为对象,e 作为 System.EventArgs)

您永远不会设置 MyLabel 的值。

你应该有类似 MyLabel.Text = "Hello";

于 2012-05-21T11:12:59.103 回答