Insert the data from the textbox into the Grid View without using any database
in ASP. NET using C#.
Step 1: To do this firstly open the Microsoft Visual Studio 2010 then
click the File->New->Web Site->select the ASP. NET website.

Step 2: The design window get appears and create a Grid View control and textbox control and button control. And set the property of controls by using the property window.


Step 3: Now
double click on the button control to write the source code of its click event.
using
System;
using
System.Collections.Generic;
using
System.Linq;
using System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Data;
public
partial class
_Default : System.Web.UI.Page
{
protected void
Page_Load(object sender,
EventArgs e)
{
dt = new
DataTable();
DataColumn dc1 =
new DataColumn("NAME");
DataColumn dc2 =
new DataColumn("ADDRESS");
dt.Columns.Add(dc1);
dt.Columns.Add(dc2);
DataRow dr1 = dt.NewRow();
GridView1.DataSource = dt;
GridView1.DataBind();
}
DataTable dt;
protected void
Button1_Click(object sender,
EventArgs e)
{
DataRow dr1 = dt.NewRow();
dr1[0] = TextBox1.Text;
dr1[1] = TextBox2.Text;
dt.Rows.Add(dr1);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
Step 4:
Run the application by pressing F5 keys and insert the value in the textboxes
then click on the button.
The Output is as
Follows:


Sirisha KPosted Aug 10, 2018, 1:15 PM
I want to add one more row without losing first row, how it possible??
lovesparks premPosted Apr 13, 2018, 5:31 AM
Which datas are insert , how to save data in text file or excel file...
Pintoo YadavPosted Aug 26, 2015, 7:04 AM
wonderful post....
Mike McDivittPosted Aug 29, 2014, 11:46 AM
How would I go about adding a new row each time a user Adds their input?
Rakesh ChavdaPosted Jun 21, 2014, 4:59 AM
nice sir ji
Satyapriya NayakPosted Jun 7, 2012, 5:25 AM
Hi Pavan, Refer the link http://www.c-sharpcorner.com/Blogs/9417/display-inserted-records-from-textbox-to-a-gridview.aspx
pavan kumarPosted Jun 6, 2012, 3:28 AM
Yupp it is working fine,,but it is working only for one record,if i enter another values old record is missing and new record is displaying,,but i want it to be displayed just next to old record..
JimJarmusch JimPosted Mar 15, 2012, 5:39 AM
Even how ordinary shoes, accompanied by gold and silver must be big hair glory. Smooth and almost shiny shoes, tie, face and heel has a unique design. Cute leopard printed on the cute girl shoes when love is hundred percent. Do not too much of the bow, would greatly eye-catching "Golden Flower" instead. Bright blue crocodile pattern has been highly lethal, Apple beaded toe equal surprise.Oxford shoes with a small tassel can be said on behalf of the casual, denim blue and pure white with, stylish and fresh. http://www.monsterearphoes.com/
Vineet Kumar SainiPosted Feb 19, 2012, 4:13 AM
It is so wonderful post....