This is a migrated thread and some comments may be shown as answers.

ListView OnItemCommand

2 Answers 148 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Guy
Top achievements
Rank 1
Guy asked on 26 Apr 2012, 06:51 PM
Hello, 
  I need to change buttons text when user clicks it, the button is in a listview
everything seems to be fine but the fact that its not showing on screen
this is part of  my code

<asp:ListView ID="TeachersList" runat="server"  OnItemCommand="ShowNumber_ItemCommand">


.
.
.

 

<ItemTemplate >

.
.
.

<asp:LinkButton ID="ShowNumberLinkButton" runat="server" CommandName="ShowNumber" CommandArgument='<%# Eval("UserID") %>' Text=" "></asp:LinkButton>
.
.
.


 

 

Protected Sub ShowNumber_ItemCommand(ByVal sender As Object, ByVal e As ListViewCommandEventArgs)

 

 

For Each row In TeachersList.Items

          For Each control In row.Controls

 

                if control.CommandArgument = UserID Then

                    control.Text = "bla bla"
.
.
.


Please help, thanks

 

2 Answers, 1 is accepted

Sort by
0
Vasil
Telerik team
answered on 01 May 2012, 09:06 AM
Hi Guy,

With this code you are changing the text correctly. However if the command was some that cause rebind, the ListView will bind again. And when it binds new controls will be created inside it's item templates. And the new controls will have the original text defined in the markup.

So you need to handle the ItemCreated or ItemDataBound events of the ListView, and change the text of the buttons there. You could still handle the ItemCommand to get the argument, but instead of setting the new text to the buttons, save it into an global variable and later on ItemCreated set the text to the newly created button.

Greetings,
Vasil
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Guy
Top achievements
Rank 1
answered on 03 May 2012, 08:37 AM
Hi,
Thanks for you quick replay.
It was the datapager that reloaded the data and cleared the changes.
Thank you and have a nice day.
Tags
ListView
Asked by
Guy
Top achievements
Rank 1
Answers by
Vasil
Telerik team
Guy
Top achievements
Rank 1
Share this question
or