Here is a solution using ajax. When you select the checkbox and click the refresh button, the jquery code will look for the selected checkbox in the gridview, and when it finds it, values ββwill be assigned for the text fields that will pop up.
You also need to save the identifier in a hidden field, on the basis of which the update request will be executed, or you can use any field on which the update will take place.
Now, when you click the update button in the popup window, an ajax request will be sent, which will take the updated values ββfrom the text fields and send them to the web method.
In the web method, you run your update request. And when ajax succeeds, you will empty the values ββof the text fields in the popup and reload the page to see the changes in the gridview.
Html popup
<div id="Popup"> <table> <tr> <td> Category </td> <td> <input type="text" id="Category" /> </td> </tr> <tr> <td> Items </td> <td> <input type="text" id="items" /> </td> </tr> <tr> <td> <input type="button" value="Update" onclick="Openselected()" /> </td> <td><input type="hidden" id="hdnID" /></td> </tr> </table> </div>
It does not appear as a popup, but you can use any plugin to show it in a popup, such as blockui, fancybox jqueryui or whatever is available.
JQuery code
This function will assign the values ββof the selected line in the text boxes and will open a pop-up window.
function Openselected() { $('table[id$=grdTest] tr').each(function () { if ($(this).find('input[type=checkbox]').is(':checked')) { $('#Category').val($(this).children('td').eq('02').text()); $('#items').val($(this).children('td').eq('03').text()); $('#hdnID').val($(this).children('td').eq('01').text()); } }); }
This function will send an ajax call with updated values ββto the web method and delete the empty text fields of the popup and reload page to see the changes
function UpdateGrid() { $.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "Default.aspx/UpdateDB", data: JSON.stringify({ category:$('#Category').val() , items: $('#items').val(),id:$('#hdnID').val() }), dataType: "json", async: false, success: function (data) { $('#Category').val(""); $('#items').val(""); $('#hdnID').val(""); window.location.reload(true); }, error: function (err) { alert(err.responseText); } }); }
Here is the web method
[WebMethod] public static string UpdateDB(string category, string items,int id) {
This is for one line only as per your requirement.