jenifer
jenifer

Reputation: 1

how to implement focus() on selected text box with in gridview

i have a text box "txtSales" with in the gridview "gvClientView",how to do focus of selected row index in different function as a name is $("#close").click(function() .

 <script type="text/javascript">
 $(document).ready(function() {
     $("table[id*=gvClientView] input[type=text][id*=txtSales]").blur(function() {
         alert($(this.val());//here i am getting value of selected text box
     });

     $("#close").click(function(){ //here i want to use focus of selected row of textbox in grid view });
 });
 </script>

Upvotes: 0

Views: 1596

Answers (1)

Shadow Wizzard
Shadow Wizzard

Reputation: 66388

I don't think the GridView expose any way to read the selected row in client side code, but if you say that in the .blur() you get proper textbox, just focus the last "blurred" textbox when clicking the button:

$(document).ready(function() {
    var lastBlurred = null;

    $("table[id*=gvClientView] input[type=text][id*=txtSales]").blur(function() {
        lastBlurred = this;
        alert($(this.val());//here i am getting value of selected text box
    });

    $("#close").click(function() {
        if (lastBlurred != null)
            lastBlurred.focus();
    });
});

Edit: to achieve what you want, you need to bind both blur() and focus() events:

$("table[id*=gvClientView] input[type=text][id*=txtSales]").bind("blur focus", function() {
        lastBlurred = this;
});

Quick test case shows the logic itself is working.

Upvotes: 1

Related Questions