I'm trying to insert a new row every time on button click function. I'm able to insert a row, but it overwrites on top of the previous row instead of creating a new row. Am I missing something?Here is my code.
void FillGrid()
{
DataTable DT=new DataTable();
DT.Columns.Add("Name", typeof(string));
DT.Columns.Add("Header", typeof(string));
if (Name.Text.Length > 0)
{
sName = QuestionText.Content;
}
if (Header.Text.Length > 0)
{
sHeader = Header.Text;
}
DT.Rows.Add(sName, sHeader);
}
public void Nrow()
{
DT.Rows.InsertAt(DT.NewRow(),0);
}
public void BindDG()
{
QuestionsGrid.DataSource = DT;
QuestionsGrid.DataBind();
}
protected void Step2AddMore_Click(object sender, EventArgs e)
{
try
{
QuestionsGrid.CurrentPageIndex = 0;
FillGrid();
Nrow();
BindDG();
}
catch (Exception ex)
{
ErrorMessage.Text = ex.ToString();
ErrorMessage.Visible = true;
}
}
void FillGrid()
{
DataTable DT=new DataTable();
DT.Columns.Add("Name", typeof(string));
DT.Columns.Add("Header", typeof(string));
if (Name.Text.Length > 0)
{
sName = QuestionText.Content;
}
if (Header.Text.Length > 0)
{
sHeader = Header.Text;
}
DT.Rows.Add(sName, sHeader);
}
public void Nrow()
{
DT.Rows.InsertAt(DT.NewRow(),0);
}
public void BindDG()
{
QuestionsGrid.DataSource = DT;
QuestionsGrid.DataBind();
}
protected void Step2AddMore_Click(object sender, EventArgs e)
{
try
{
QuestionsGrid.CurrentPageIndex = 0;
FillGrid();
Nrow();
BindDG();
}
catch (Exception ex)
{
ErrorMessage.Text = ex.ToString();
ErrorMessage.Visible = true;
}
}