As per your code you written
DataRow dr = dtSource.NewRow();
dtSource.Rows.Add(DateTime.Now, itemDetail, "", "");
May this solution help you:
protected void btn1_Click(object sender, EventArgs e)
{
if(!string.IsNullOrEmpty(text1.Text))
{
string itemDetail = text1.Text;
DataTable dtSource = ViewState["dtSource"] as DataTable;
if(dtSource.Rows.Count<16)
{
foreach(DataRow dr in dtSource.Rows)
{
if (dr["DateTime"].ToString() == "" && dr["Detail"].ToString() == " ")
{
dr["DateTime"] = DateTime.Now.ToString();
dr["Detail"] = itemDetail;
break;
}
}
}
else{
DataRow dr = dtSource.NewRow();
dtSource.Rows.Add(DateTime.Now, itemDetail, "", "");
}
grid1.DataSource = dtSource;
grid1.DataBind();
ViewState["dtSource"] = dtSource;
}
}