Hi All,
I am trying to add blank rows in between gridview rows. The existing rows contains textbox controls as well. On initial get request the page is rendered correctly with proper value in respective textboxes. But on button click outside the gridview, the value of textbox of first grid row after the inserted new row is getting shifted to the new row in a textbox control. While inserting new row, there was no textbox control.
public void AddNewRow(object sender, GridViewRowEventArgs e)
{
GridView GridView1 = (GridView)sender;
GridViewRow NewTotalRow = new GridViewRow(0, 0, DataControlRowType.EmptyDataRow, DataControlRowState.Insert);
NewTotalRow.Font.Bold = true;
NewTotalRow.BackColor = System.Drawing.Color.Blue;
TableCell HeaderCell = new TableCell();
HeaderCell.Height = 25;
HeaderCell.HorizontalAlign = HorizontalAlign.Center;
HeaderCell.ColumnSpan = 10;
HeaderCell.ForeColor = System.Drawing.Color.White;
HeaderCell.Text = "1st Level Subordinates";
NewTotalRow.Cells.Add(HeaderCell);
GridView1.Controls[0].Controls.AddAt(e.Row.RowIndex + rowIndex, NewTotalRow);
rowIndex++;
}
protected void cmdBtn_saveSubmit_Click(object sender, CommandEventArgs e)
{ foreach (GridViewRow gvRow in grid_score.Rows)
{
if (gvRow.RowType != DataControlRowType.EmptyDataRow)
{
TextBox txtscore = gvRow.Cells[7].FindControl("txtbox") as TextBox;
string score = txtscore.Text.ToString();
if (score =="")
{ System.Web.UI.ScriptManager.RegisterStartupScript(this, GetType(), "displayalertmessage", "alert('alert');", true);
return;
}
}
}
}
What I have tried:
here after return statement, when the page reappears, the formatting of emptydatarow is getting removed. Also when checking emptydatarow, it is showing as normal datarow and value of textbox just below emptydatarow is getting shifted to textbox in empty row.