简体   繁体   English

发送选定的jquery datatables行到服务器端c#asp.net

[英]send jquery datatables rows selected to server side c# asp.net

function Delete() 
     {
         var iTable = $('#Dims').DataTable();
         var rows = iTable.rows('.selected').indexes();             
         document.getElementById('<%=hdnRows.ClientID %>') = rows;  

     }

I am trying to get the rows selected in the datatable and put it into a hidden field named hdnRows so I can delete the selected rows from a list I am using to populate the datatable. 我正在尝试获取数据表中选定的行,并将其放入名为hdnRows的隐藏字段中,以便可以从用于填充数据表的列表中删除选定的行。 I am not sure what type the rows variable is since it can contain several indexes (it must be a array). 我不确定rows变量的类型是什么,因为它可以包含多个索引(必须是数组)。

I tried using a for loop and running through the variable rows and adding it to hdnRows in a comma delimited string. 我尝试使用for循环并遍历变量行,并将其以逗号分隔的字符串添加到hdnRows中。

 for (var i = 0; i < length; i++) {
             document.getElementById('<%=hdnRows.ClientID %>') += rows[i] + ',';
         }

This didn't put anything into the hidden field either. 这也没有在隐藏字段中添加任何内容。 I even tried hard coding a number in just to see if it would work 我什至尝试硬编码一个数字只是为了看看它是否有效

document.getElementById('<%=hdnRows.ClientID %>') = '3'; 

I am executing a javascript function called delete from the onclientclick method of asp button. 我正在执行一个JavaScript函数,该函数从asp按钮的onclientclick方法中删除。

<asp:Button ID="btnDelete" runat="server" OnClientClick="Delete()" Text="Del" />

Everything I read says this should work. 我读过的所有内容都说应该可以。 If anyone answers the question be sure to indicate the data type of var rows. 如果有人回答该问题,请确保指示var行的数据类型。

Once on the server side I just need to delete the selected rows from a 一旦在服务器端,我只需要从

List<structs>

I am using to populate table 我用来填充表格

I was very close. 我离得很近。

document.getElementById('<%=hdnRows.ClientID %>').value = rows[0].toString();

The main things to remember are 要记住的主要事情是

  1. You need the .value after you get the element(hidden field) by id. 通过id获取元素(隐藏字段)后,需要.value。 Be sure to use small v not capital V as the latter won't work and on the server side it's capital V 确保使用较小的v而不是大写的V,因为后者将不起作用,并且在服务器端使用大写的V

  2. The hidden field stores a string so be sure to ad the .toString() method if your using a number. 隐藏字段存储字符串,因此如果您使用数字,请确保添加.toString()方法。

On a side note the rows variable is an array. 从侧面看,rows变量是一个数组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM