Q:

jquery asp.net listview

I have a asp.net webapp and I am using Jquery.  I wanted to know how can I pull data out of created table on the client side.  I tried a few different ways but known work.  I just want to be able to say when click alert the data in the row from a hidden class i got with a UID.  Please note this is asp.net not regular html.  So to sum it up I have a listview that creates a table, and each row thats created I store the ID in a 333-444-556-66 like that.  And when a user clicks on a row I alert that ID from that class.  Thanks

A:

The easiest way to do this is to forget about the fact that this is ASP.NET and start treating it like HTML.  So you need to pass an ID to the client?  Just add it to the HTML, e.g. in your markup:
<ItemTemplate>
    <asp:TableRow id="TemplateRow" datakey='<%# Eval("MyDataKeyField")>' %> />
    ...
</ItemTemplate>

or in code:
override void OnInit(EventArgs e) {
     ListView1.ItemDataBound += new 
         EventHandler<ListViewItemEventArgs>(ListView1_ItemDataBound);
}

protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
{
    TableRow row = e.Item. FindControl("TemplateRow");
    row. Attributes["datakey"]=((MyDataSourceType)e. Item. DataItem).MyDataKeyField;
}

so now you will have HTML that renders like this:
<table class="myDataTable">
   <tr id="$some$insane$asp$dot$net$id" datakey="555-66">
      <td> ... </td>...
   </tr>
   ...
</table>

Then in jQuery.  Ignore the asp.net ID.  It is of no use to anyone but asp.net.  Your own ID, however, is exactly as you rendered it.  So just grab it. 
$(document).ready(function() {
   $('.myDataTable tr').click(function(e) {
       var $my_id = $(this).attr('datakey');
       alert($my_id);
  });
});

