Are you certain the the function
Page_Load
is executed?
Looks to me like your columns are never added to the
DataTable
.
Have you tried to set a break point inside
Page_Load
to see if the debugger stops there?
And to avoid that you try to add the columns twice you could change the code like this
DataTable dt = null;
protected void Page_Load(object sender, EventArgs e)
{
dt = new DataTable();
dt.Columns.Add(new DataColumn("itemname", typeof(string)));
dt.Columns.Add(new DataColumn("itemprice", typeof(double)));
dt.Columns.Add(new DataColumn("quantity", typeof(int)));
dt.Columns.Add(new DataColumn("tax", typeof(double)));
dt.Columns.Add(new DataColumn("finalamount", typeof(double)));
}
or
DataTable dt = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
if (dt.Columns.Count == 0)
{
dt.Columns.Add(new DataColumn("itemname", typeof(string)));
dt.Columns.Add(new DataColumn("itemprice", typeof(double)));
dt.Columns.Add(new DataColumn("quantity", typeof(int)));
dt.Columns.Add(new DataColumn("tax", typeof(double)));
dt.Columns.Add(new DataColumn("finalamount", typeof(double)));
}
}
[UPDATE]
Navigating through Code with the Debugger[
^]
How to: Set a Simple Breakpoint[
^]