A. Dubey A. Dubey - 2 months ago 9
C# Question

How to pass and retrieve table row data using QueryString in asp.net

I have a DataTable

I have created this

var a=[];
$("#DataTable tbody").on( 'click', 'tr', function ()
{
a=table.row( this ).data();
});


Now I want to pass this array a[] to another web form using query string on button click

<asp:Button ID="button" onclick="click_function"/>


And then

[WebMethod]
click_function()
{
var darr = [];
darr = table.row('.selected').data();

var url = "QuestionDetail.htm?QuestionId=" + darr;
window.location.href = url;
}


How should I?

And also I have to retrieve this array in that new webform. So, that I will get data of that row

Ted Ted
Answer

I'm guessing that

// JavaScript    
var table = $("#DataTable").DataTable();

If that's the case then I would add a hidden field on the form

<!-- HTML -->
<input type="hidden" runat="server" id="hfSelectedRow" />

and set the data to that field

// JavaScript
$("#DataTable tbody").on( 'click', 'tr', function () 
{       
    $('#hfSelectedRow').val(table.row( this ).data());
});

so now on the server you can retreive the data by

[WebMethod]
protected void button_click() 
{
    Response.Redirect("QuestionDetail.htm?QuestionId=" + hfSelectedRow.Value);
}