I have grid view with out any record and i want to add text box values into grid view using jQuery without using c#.
-
2what have you tried so far, any sample? stackoverflow.com/help/how-to-askFarooq Ahmed Khan– Farooq Ahmed Khan2017-01-08 14:55:03 +00:00Commented Jan 8, 2017 at 14:55
-
Please add your code. Just a snapshot is not good enough. Please refer How to ask and provide necessary detailsRajesh Dixit– Rajesh Dixit2017-01-08 14:55:06 +00:00Commented Jan 8, 2017 at 14:55
-
A. do you mean when you have no records? B. Do you need that the value in that textbox will send to the server?Mosh Feu– Mosh Feu2017-01-08 15:02:11 +00:00Commented Jan 8, 2017 at 15:02
-
i have used below url for reference . but in that code they are using c# code to add first row. i want with out using c#. aspsnippets.com/Articles/…user3279300– user32793002017-01-08 15:07:56 +00:00Commented Jan 8, 2017 at 15:07
-
@MoshFeu : A. i want add records dynamically. B. after button click on onClientClick the textbox values should be added into gridview. i want client side coding .user3279300– user32793002017-01-08 15:23:04 +00:00Commented Jan 8, 2017 at 15:23
|
Show 1 more comment
1 Answer
If the Id attribute is static (if not, add CssClass attribute to the GridView) then you can just append the textbox using jQuery
function addRecord() {
var record = $('#newRecord').val();
addRow(record);
$('#newRecord').val('');
}
function addRow(value) {
$('#GridView1 tbody').append('<tr><td>' + value + '</td></tr>');
}
table, td, th {
border: 1px solid;
border-spacing: 0;
}
<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>
2 Comments
user3279300
actually i want to add values in grid view only and i want to edit and delete the records with out using c# and JSON
