Cant reference cell text

A

Assimalyst

Hi,

I'm attempting an update SQl Server using a gatagrid using ADO.

I am having trouble getting a changed value to work however.

The datagrid is populated as below:

sampleNo brush biopsy lavage histology patinetNo
Edit 87 True True True Squamous 67

The only editable column is histology.

I am using the following code to try to update any changes to that
cell:

DataRow sRow = dsSample.Tables["Table"].Rows[0];
sRow["Histology"] = ((TextBox)e.Item.Cells[5].Controls[0];

But no update occurs. If i change it to:

DataRow sRow = dsSample.Tables["Table"].Rows[0];
sRow["Histology"] = "New Text";

Then it does update. So it seems my cell referencing is wrong. Can
anyone tell me why? I have tried changing the [5] and [0], but get
errors.

Thanks.
 
B

Brock Allen

Put a breakpoint in the debugger to see how many child controls are under
the Cell -- there may be more than one if it's a template column.
 
A

Assimalyst

Thanks for the suggestion Brock.

I've put a breakpoint in the debugger, i then expanded 'e' then 'Item'
and found there are listings for 'Cells' and 'cells', i've expanded
these and the 'owner', then get an option again of expanding 'Cells'
and 'cells' (amongst others), and it seems i can continue expanding
'Cells' then 'owner' for quite some time . . .

Not really sure what i'm looking for from here. Could you point me in
the right direction please?

Thanks again.
 
E

Elton Wang

You can't assign a control, TextBox, to ["Histology"]. You should use a
string value to update sRow["Histology"] like :
TextBox txtHistology = ((TextBox)e.Item.Cells[5].Controls[0];
sRow["Histology"] = txtHistology.Text;


HTH
 
A

Assimalyst

Thanks Elton,

Tried that, but still getting the same behaviour as above. The database
is not updating.

I can only presume something is wrong with the
((TextBox)e.Item.Cells[5].Controls[0]) statement. But what??

Thanks again.
 
E

Elton Wang

One most likely reason is that data in the textbox is overwritten by data
from database. You might rebind the datagrid's data source before performing
update function. Normally, we should bind the datagrid's data source when
IsPostback = false.



HTH
 

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

Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top