views:

195

answers:

1

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.

+1  A: 

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.

Alexander Gyoshev