Reputation: 71
i have a gridview with 6 columns in 5th column i have placed a text box, all the data are populating in the grid by executing stored procedure from database .
i have another textbox and ok button outside the gridview also.
Now i need to update the text box value in the gridview with the same text which is added to the outside the text box inside ok button click event ..
how can i do this without saving data to database?through javascript or jquery?
Upvotes: 0
Views: 1172
Reputation: 21795
First thing if you are using ASP.NET 4 or above then you can set the ClientIDMode
of your controls to Static so that it will be easier to work with the controls in jQuery. Alternatively you can also add custom attributes or class to your controls. Now since a gridview is rendered as html table in browser you can find the second row in the table (since first row is header row) and update the value like this:-
$(document).ready(function () {
$("#btnSubmit").click(function (e) {
e.preventDefault();
var firstRow = $('tr:nth-child(2)', $('#GridView1'));
var outsideText = $('#txtOutside').val();
$('#txtfoo', firstRow).val(outsideText);
});
}
Here I have considered that the ID of your gridview control is GridView1
, the textbox which is outside is txtOutside
, button is btnSubmit
and the textbox which is outside is txtOutside
.
Upvotes: 1