答案 0 :(得分:1)
如果Id
属性是静态的(如果没有,请将CssClass
属性添加到GridView),那么您可以使用jQuery附加文本框
function addRecord() {
var record = $('#newRecord').val();
addRow(record);
$('#newRecord').val('');
}
function addRow(value) {
$('#GridView1 tbody').append('<tr><td>' + value + '</td></tr>');
}
&#13;
table, td, th {
border: 1px solid;
border-spacing: 0;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- Let's say that the gridview rendrer as table-->
<table id="GridView1">
<thead>
<tr>
<th>Col 1</th>
</tr>
</thead>
<tbody>
<!-- It's empty because of no records-->
</tbody>
</table>
<input id="newRecord" type="text" placeholder="Record to add" />
<!-- button with OnClientClick will render as onclick html attribute -->
<button onclick="addRecord()">Add a record</button>
&#13;