Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Cant reference cell text

Reply
Thread Tools

Cant reference cell text

 
 
Assimalyst
Guest
Posts: n/a
 
      09-05-2005
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.

 
Reply With Quote
 
 
 
 
Brock Allen
Guest
Posts: n/a
 
      09-05-2005
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.

-Brock
DevelopMentor
http://staff.develop.com/ballen



> 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.
>




 
Reply With Quote
 
 
 
 
Assimalyst
Guest
Posts: n/a
 
      09-06-2005
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.

 
Reply With Quote
 
Elton Wang
Guest
Posts: n/a
 
      09-06-2005
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



"Assimalyst" <> wrote in message
news: oups.com...
> 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.
>



 
Reply With Quote
 
Assimalyst
Guest
Posts: n/a
 
      09-06-2005
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.

 
Reply With Quote
 
Elton Wang
Guest
Posts: n/a
 
      09-06-2005
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





"Assimalyst" <> wrote in message
news: oups.com...
> 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.
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
cant compile on linux system.cant compile on cant compile onlinux system. Nagaraj C++ 1 03-01-2007 11:18 AM
man i cant belive i cant get help please unclejesse01 DVD Video 2 04-14-2005 03:15 PM
How to set and highlight text in JTable cell on selection and/or invoke cell editor directly. news.rcn.com Java 1 07-12-2004 10:22 PM
How do I have a table cell fetch another page to display within the cell? Phillip Roncoroni HTML 14 04-05-2004 05:58 PM
multilink cell phones multilinking shotgun 2 cell phones Calvin Cisco 1 11-07-2003 02:20 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57