Getting value of a GridView cell

T

TisMe

Hi All,

Can anyone help me out here?

I am trying to get the value of a GV cell, code is below (Obviously
not useful - But this is what I have ended up with during my testing).

I have bound columns and template columns - e.Row.Cells.text() is
always an empty string!

Cheers!
Simon.

protected void GVContacts_RowCreated(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{

for (int i = 0; i < e.Row.Cells.Count; i++)
{
this.Label1.Text += e.Row.Cells.text();
}
}
}
 
A

aplocher

Hi All,

Can anyone help me out here?

I am trying to get the value of a GV cell, code is below (Obviously
not useful - But this is what I have ended up with during my testing).

I have bound columns and template columns - e.Row.Cells.text() is
always an empty string!

Cheers!
Simon.

protected void GVContacts_RowCreated(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{

for (int i = 0; i < e.Row.Cells.Count; i++)
{
this.Label1.Text += e.Row.Cells.text();
}
}
}


Weird that it's empty and not throwing an exception or even a
compilation error. text() doesn't exist, it should be Text. It's a
property not a method. So...

this.Label1.Text += e.Row.Cells.Text;
 
B

bob clegg

Hi All,

Can anyone help me out here?

I am trying to get the value of a GV cell, code is below (Obviously
not useful - But this is what I have ended up with during my testing).

I have bound columns and template columns - e.Row.Cells.text() is
always an empty string!

Cheers!
Simon.

protected void GVContacts_RowCreated(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{

for (int i = 0; i < e.Row.Cells.Count; i++)
{
this.Label1.Text += e.Row.Cells.text();
}
}
}

Hi,
You have the code in the Row created handler. Is it possible that the
data is not bound yet?
Have you tried the RowDataboundEvent?
Bob
 
C

Chris Shepherd

TisMe said:
Hi All,

Can anyone help me out here?

I am trying to get the value of a GV cell, code is below (Obviously
not useful - But this is what I have ended up with during my testing).

I have bound columns and template columns - e.Row.Cells.text() is
always an empty string!


That's because DataGridViewCells store their data in the Value property.
What you're looking for is:

e.Row.Cells.Value.ToString();


Chris.
 
T

TisMe

That's because DataGridViewCells store their data in the Value property.
What you're looking for is:

e.Row.Cells.Value.ToString();


Chris, thanks but there doesnt seem to be a value property!?...

Compiler Error Message: CS0117: 'System.Web.UI.WebControls.TableCell'
does not contain a definition for 'Value'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top