views:

322

answers:

2

I want to use jQuery with a GridView which contains textboxes, but I'm stuck on how to get event listeners registered for every textbox on the selected row. I was thinking I could do something with a StingBuilder in the Unload event of the GridView but I can't get it working.

+1  A: 

Why not just add a CSS class to each TextBox and use a jQuery selector to find them?

<asp:GridView runat="server">
  <Columns>
    <asp:BoundField ControlStyle-CssClass="someclass" DataField="xxx" />
  </Columns>
</asp:GridView>

Then you should be able to do...

$().ready(function() {
  $(".someclass").function() {
   //do something interesting
  }
});
Macka
A: 

If you have many textboxes (which it sounds like you do) better to delegate the event to some parent container rather than attach lots of events (event delegation) Start reading here

redsquare