Search code examples
c#asp.netlistviewcellselecteditem

listview select row without postBack


I have a list view with many rows and have it set so that if you click on a cell it highlights it.

When clicking on the first column cells the whole row is highlighted (SelectedItemTeplate of listvew) the problem is that when you select a row all the highlighted cells gets reset as the page refreshes.

Is it possible to just highlight without postback?


Solution

  • Is it possible to just highlight without postback?

    Yes, do this highlighting entirely on the client side via JQuery or Javascript.

    For example, assuming every row in the listview has a class applied, you can do this in JQuery:

    $(document).ready(function(){
    
       $('.your_class').live("click",function() { $(this).attr("class","highlight");   });
    
    });
    

    What the above code will do is that any html element in your page that has the class ".your_class" applied, will change to another class ("highlight" on the example) when it's clicked.