This is my code iam trying to display the data in gridview which is entered in the input text box fields after hitting the submit button.
There is no error but the data is not add to the table it just shows the empty table
public partial class Default : System.Web.UI.Page
{
DataRow dr;
DataTable dt = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
dt.Columns.Add(new DataColumn("ID", typeof(int)));
dt.Columns.Add(new DataColumn("Name", typeof(string)));
dt.Columns.Add(new DataColumn("Salary", typeof(int)));
dt.Columns.Add(new DataColumn("Department", typeof(string)));
dr = dt.NewRow();
dr["ID"] = txtID.Text;
dr["Name"] = txtName.Text;
dr["Salary"] = txtSalary.Text;
dr["Department"] = txtDepartment.Text;
dt.Rows.Add(dr);
GridView1.DataSource = dt;
GridView1.DataBind();
