Saturday, February 19, 2011

ASP.NET jQuery - Bound Controls

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.

From stackoverflow
  • 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
      }
    });
    
  • 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

0 comments:

Post a Comment