Asp net grid view select row using jquery

I have a normal gridview on asp.net web page… I want to select a row using jquery and then pressing a button to send the id and descripcion columns to a web service…

My question is how can I select the row and get the information I want… all using jquery.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Try something like

$('#<%=Grid.ClientID %>').delegate('tr', 'click', function(){
    $('#<%=Grid.ClientID %> tr').not(this).removeClass('selectedRow');
    $(this).toggleClass('selectedRow'); 
});

This should enable you to select a single GridView row on click.

After that, for the button control, use the following

$('#<%=Btn.ClientID %>').click(function(){
    alert($('#<%=Grid.ClientID %>').find('tr.selectedRow').html());

    // code to call the webservice using columns from $('#<%=Grid.ClientID %>').find('tr.selectedRow')

    // prevent Button control from causing a postback
    return false;
});


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x