0

I have grid view with out any record and i want to add text box values into grid view using jQuery without using c#.

enter image description here

6
  • 2
    what have you tried so far, any sample? stackoverflow.com/help/how-to-ask Commented 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 details Commented 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? Commented 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/… Commented 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 . Commented Jan 8, 2017 at 15:23

1 Answer 1

1

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>

Sign up to request clarification or add additional context in comments.

2 Comments

@user3279300 A. You can post each value when you add it to the table. B. You can build a JSON from the table and send it to the server when you want. (Something like this
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.