fiaolle 0 Newbie Poster

I can't change the text of a linkbutton that is placed in a repeater. I want the text to change when I click the button.

<asp:Repeater ID="rptSearch" runat="server" >
<HeaderTemplate >
<table border="1" width="100%">			
<tr>
<th>
Bild
</th>
<th>
<asp:LinkButton ForeColor="Blue" Text="Visa billig" OnClick="SortList" EnableViewState="true"
ID="lkbSort" runat="server"></asp:LinkButton>
</th>
</tr>
</HeaderTemplate>
<ItemTemplate >
<tr>
<td>
<asp:Image BorderStyle="Solid" BorderColor="#ff7200" BorderWidth="1px" runat="server" ID="imgBild" ImageUrl='<%# imageURL(DataBinder.Eval(Container.DataItem, "fldImageID")) %>' />
</td>
<td>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>	
</asp:Repeater>

I have tried with th OnClick event, doesnt work.

Sub SortList(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim a As System.Web.UI.WebControls.LinkButton = sender
        If a.Text = "Visa billig" Then
            a.Text = "Visa ny"
        ElseIf a.Text = "Visa ny" Then
            a.Text = "Visa billig"
        End If
         ShowSearch()
    End Sub

Have also tried these events, rptSearch_ItemCreated and rptSearch_ItemDataBound, but the text just changes one time. I see when I debug that the linkbutton's text is still "Visa billig", but shows "Visa ny"

Protected Sub rptSearch_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptSearch.ItemCreated
        If e.Item.ItemType = ListItemType.Header Then
            'this is one way
            Dim lnk As LinkButton = CType(e.Item.FindControl("lkbSort"), LinkButton)
            If IsNothing(lnk) Then
                Exit Sub
            End If
                If lnk.Text = "Visa billig" Then
                    lnk.Text = "Visa ny"
                ElseIf lnk.Text = "Visa ny" Then
                    lnk.Text = "Visa billig"
                End If
              End If
    End Sub

I am new to asp.net but I think it may have to do with postback's. And I have tried to use findControl in page_load to change the linkbutton's text, but the linkbutton isn't found.

If rptSearch.Items.Count > 0 Then
            Dim lkbSort As LinkButton = CType(rptSearch.FindControl("lkbSort"), LinkButton)
            If Not IsNothing(lkbSort) Then
                lkbSort.Text = ViewState("Change")
            End If
  End If

PLEASE HELP
Thanks
Fia