accessing jquery datatable's selected row's column value in asp.net
How do you access the selected row value in a jquery datatable in asp.net code behind? I am using an asp.net webforms project without any server side processing on the jquery datatable (dont need ajax callbacks here)
I have created a jquery datatable dynamically by writing the table (through c#) 开发者_如何转开发and initializing it via javascript. No issues here - the table is created and working as expected.
Now, when a user clicks on a specific row, I need to be able to read a specific column value of the selected row in code behind for processing. Any idea on how to implement this?
Never worked with JQuery DataTable but i can suggest you to add a Javascript function on the rows click and do a $.post to your ASPX page with the data you need...
For some example you can go Here or use this code :
public partial class _Default : Page
{
[WebMethod]
public static string GetDate()
{
return DateTime.Now.ToString();
}
}
and use this javascript to send data...
$.ajax({
type: "POST",
url: "PageName.aspx/MethodName",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
// Do something interesting here.
}
});
Maybe there are more elegant solutions...
i don't know anything about asp.net but there is a really ince way to send data from your datatables integrating a plugin called jeditable. Here is a basic example and here you find more complex one. Basically if you want to edit a cell in the table, you double click it and it becomes an input field. When you press Return, you send the edited data to the server, with some added parameters (Usually i create my markup assign the id of the row in the database to the id attribute of the <tr>
.
Thank you for the responses. I found a solution that did not require writing ajax calls. We are just setting a hidden field value in javascript when a row is clicked. This value is read on the server side during post back.
精彩评论