我有以下的Javascript功能來複制選中(使用複選框)行值從Gridview1到GridView2。如何添加選擇和GridView的刪除按鈕使用JavaScript
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
var temprow = $('[id*=GridView2] table tbody').find(".emptyTd");
$('[id*=cbCheck]').change(function() {
var checkbox = $(this);
if ($(this).is(":checked")) {
var row = $(this).parent().closest('tr');
var temp = $(row).clone(true);
$('[id*=GridView1] tbody').append(temp);
$('[id*=GridView2] table tbody').find(".emptyTd").remove();
$(row).find("td:first").remove();
$('[id*=GridView2] table tbody').append(row);
}
else {
$('[id*=GridView2] table tbody tr').each(function() {
if ($(this).find("td:first").html() == $(checkbox).parent().closest('tr').find("td:nth-child(2)").html()) {
$(this).remove();
if ($('[id*=GridView2] table tbody').has('td').length == 0) {
$('[id*=GridView2] table tbody').append(temprow);
}
}
});
}
});
});
</script>
現在我想添加使用Javascript/jQuery的在GridView2 SELECT
和DELETE
按鈕。
我GidView2樣子:
<asp:GridView ID="GridView2" HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White"
runat="server" AutoGenerateColumns="false" OnSelectedIndexChanged="GridView2_SelectedIndexChanged">
<EmptyDataTemplate>
<table border="0" cellpadding="0" cellspacing="0" width="325px">
<tr style="color: White; background-color: #3AC0F2;">
<th scope="col">
Item Code
</th>
<th scope="col">
Item Name
</th>
<th scope="col">
Unit
</th>
<th scope="col">
Price
</th>
<th scope="col">
Stock
</th>
</tr>
<tr class="emptyTd">
<td style="width: 30px; text-align: center" colspan="3">
No Records found
</td>
</tr>
</table>
</EmptyDataTemplate>
</asp:GridView>
你打算用這些按鈕做什麼?使用Javascript創建的內容將在頁面刷新/回傳時丟失。他們將沒有與asp.net相關的功能。 – VDWWD