Asp net grid view select row using jquery

后端 未结 1 1839
野性不改
野性不改 2021-01-25 16:02

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...

相关标签:
1条回答
  • 2021-01-25 16:38

    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;
    });
    
    0 讨论(0)
提交回复
热议问题