更改树视图选择的节点更改中的转发器标签

时间:2012-05-21 11:08:34

标签: asp.net vb.net

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

 <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和值。在选定的节点更改事件上,我想更改转发器所选节点的文本。我正在编写这样的代码:

受保护的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

但这并不是对MyLabel文本的欺骗。如何解决?

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

此致 Asif Hameed

1 个答案:

答案 0 :(得分:0)

在方法中,

TreeView1_SelectedNodeChanged(sender As Object,e As System.EventArgs)

您永远不会设置MyLabel的值。

你应该有类似MyLabel.Text =“你好”的东西;