I have a repeater control with item template like this:
<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>
and itemCommand event where I am changing the repeater row color and saving its id in viewstate like this:
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
I have a treeview on this page of which each node has and Id and value. on selected node change event, I want to change the text of repeater selected node. I am writing code like this:
Protected Sub TreeView1_SelectedNodeChanged(sender As Object, e As System.EventArgs) Handles 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
But It is not chagging MyLabel text. How to fix it ?
Both treeview and repeater are populated in !Page.Ispostback event
Regards, Asif Hameed