Hello,
Every time you are generating new object of
DataTable
in button click and then checking whether it contains any row or not . Obviously it does not contain any row. That's Why data is not showing .
First declare the Table globally means out side of button Click and define its columns
In button click event change the code by this way
DataRow dr =dt.NewRow();
dt.Rows.Add(txt1.Text, txt2.Text);
if (dt.Rows.Count > 0)
{
grid1.ItemsSource =null;
grid1.ItemsSource = dt.DefaultView;
}
Thanks