简体   繁体   中英

How can we make the DataView Control respond to javascript events?

If I had an ASP.NET 4.0 DataView control that looked like below, how can I control javaScript events on the client side?

Body tag:

<body xmlns:sys="javascript:Sys" xmlns:dataview="javascript:Sys.UI.DataView"    
  sys:activate="*">

DataView tag:

<ul sys:attach="dataview" dataview:data="{{ ListOfPeople }}" class="sys-template">    
    <li>    
          <div>{{ GivenName }}</div>  
          <div>{{ SurName }}</div>  
          <div>{{ Title }}</div>  
          <div>{{ Department }}</div>  
          <div>{{ Phone }}</div>  
          <div>{{ EmailAddy }}</div>  
    </li>  
</ul>

For instance, I want a button or link to 'select' this record and have the server send them an email or flag them in the database or even something as simple as changing the style of the selected row so as to bring the user's focus to it.

AFAIK the client templates are used rendering and do not have any options to attach events.

I guess using jQuery you could implement a simple selection

$('#peopleList > li').live('click', function () {
    $(this).parent().children().removeClass('selected');
    $(this).addClass('selected');
});

The case with the button can be handled by adding it through the client template and binding the events in a similar way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM