ListView OnItemCommand

3 posts, 0 answers
  1. Guy
    Guy avatar
    2 posts
    Member since:
    Apr 2012

    Posted 26 Apr 2012 Link to this post

    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. Vasil
    Admin
    Vasil avatar
    1547 posts

    Posted 01 May 2012 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Guy
    Guy avatar
    2 posts
    Member since:
    Apr 2012

    Posted 03 May 2012 Link to this post

    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.
Back to Top