I have a code:
protected void gvContacts_RowDatabound(object sender, GridViewRowEventArgs e)
{
Label label = new Label();
label.Text = "test";
if (e.Row.RowType == DataControlRowType.DataRow && e.Row.RowIndex == 0)
{
for (int i = 0; i < e.Row.Cells.Count; i++)
{
e.Row.Cells[i].Controls.Add(label); //doesnt work
e.Row.Cells[i].Text = "this works";
}
}
}
where label does not appear to my cells. What’s wrong?
You need create a new instance of your label in each loop