Here it is,
HTML
<asp:GridView ID="gvCustomers" CssClass = "table" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField HeaderText="Name" ItemStyle-Width="150px" ItemStyle-CssClass="Name">
<ItemTemplate>
<%# Eval("Name") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Country" ItemStyle-Width="150px" ItemStyle-CssClass="Country">
<ItemTemplate>
<%# Eval("Country")%>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br />
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td style="width: 150px">
Name:<br />
<asp:TextBox ID="txtName" runat="server" Width="140" Text="" />
</td>
<td style="width: 150px">
Country:<br />
<asp:TextBox ID="txtCountry" runat="server" Width="140" Text="" />
</td>
<td style="width: 100px">
<br />
<asp:Button ID="btnAdd" runat="server" Text="Add" />
</td>
</tr>
</table>
<br />
<asp:Button Text="Reload" runat="server" />
VB.Net
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Me.BindGrid()
End If
End Sub
Private Sub BindGrid()
Dim dt As New DataTable()
dt.Columns.AddRange(New DataColumn() {New DataColumn("Name", GetType(System.String)), New DataColumn("Country", GetType(System.String))})
If (dt.Rows.Count = 0) Then
dt.Rows.Add()
End If
gvCustomers.DataSource = dt
gvCustomers.DataBind()
End Sub
JavaScript
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$("[id*=btnAdd]").click(function () {
//Reference the GridView.
var gridView = $("[id*=gvCustomers]");
//Reference the first row.
var row = gridView.find("tr").eq(1);
//Check if row is dummy, if yes then remove.
if ($.trim(row.find("td").eq(0).html()) == "") {
row.remove();
}
//Clone the reference first row.
row = row.clone(true);
//Add the Name value to first cell.
var txtName = $("[id*=txtName]");
SetValue(row, 0, "name", txtName);
//Add the Country value to second cell.
var txtCountry = $("[id*=txtCountry]");
SetValue(row, 1, "country", txtCountry);
//Add the row to the GridView.
gridView.append(row);
return false;
});
function SetValue(row, index, name, textbox) {
//Reference the Cell and set the value.
row.find("td").eq(index).html(textbox.val());
//Create and add a Hidden Field to send value to server.
var input = $("<input type = 'hidden' />");
input.prop("name", name);
input.val(textbox.val());
row.find("td").eq(index).append(input);
//Clear the TextBox.
textbox.val("");
}
});
</script>
In short I just removed the SELECT and INSERT Statement
I dont know how to save it in JAVASCRIPT Side
I think you used this code to save it int JAVASCRIPT
protected string Values;
But I don't know how to use, thanks