Question

I could post several links to articles of people asking the very same question, not necessarily on Stack Overflow, but I don't know why this does not work for me.

My code is:

int rowIndex = ((GridViewRow)(((CheckBox)sender).Parent.Parent)).RowIndex;
Label lbl = new Label();
lbl.ID = "test" + testing.ToString();
lbl.Text = gvBatters.Rows[rowIndex].Cells[1].Value;
upCompare.ContentTemplateContainer.Controls.Add(lbl);
testing++;

My problem is on this line:

lbl.Text = gvBatters.Rows[rowIndex].Cells[1].Value;

The problem being Value. It does not like this, says I'm missing an assembly reference to System.Web.UI.WebControls.TableCell. I am in fact using System.Web.UI.WebControls

When I try the line like this:

lbl.Text = gvBatters.Rows[rowIndex].Cells[1].ToString();

It shows up in my update panel with the label text as:

System.Web.UI.WebControls.DataControlFieldCell

I am so close. All my Google searches say I should have .value, but visual studio says no.

Était-ce utile?

La solution

Try .text. I can't remember for sure but I think that will get the text if it's a bound field.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top