Home > DeveloperSection > Forums > insert data in datagridview from text box c#
Ankit Singh

Total Post:341

Points:2389
Posted on    February-08-2016 10:33 PM

 C# C#  Datagridview 
Ratings:


 1 Reply(s)
 300  View(s)
Rate this:
we want to insert data in datagridview from text box c#. how to do this please help me.


aditya kumar Patel

Total Post:246

Points:1752
Posted on    February-08-2016 10:45 PM

here we are going to insert data in datagridview from text box dynamically using c# code windows application.
we are provide demo code and design.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsForums
{
public partial class FORUM : Form
{
public FORUM()
{
InitializeComponent();
}
DataTable dt = new DataTable();

private void FORUM_Load(object sender, EventArgs e)
{
dt.Columns.Add("Name");
dt.Columns.Add("Email");
dataGridView1.DataSource = dt;
dataGridView1.Columns[0].Width = 200;
dataGridView1.Columns[1].Width = 300;

}

private void btnupdate_Click(object sender, EventArgs e)
{

DataRow dr = dt.NewRow();
dt.Rows.Add(dr);
dr[0] = txtname.Text;
dr[1] = txtemail.Text;
dataGridView1.DataSource = dt;

}
}
}



Don't want to miss updates? Please click the below button!

Follow MindStick