Simple question: e.Item.Cells(0).Controls­(0)

D

davidfox789

I am new at this.. probably not proficient enough to even consider
myself a Newbie yet. :)

I have a DataGrid with Template columns. After the user edits a field
in the DataGrid and presses Update, the UpdateCommand code executes no
problem. However...

Normally I read the newly edited contents of a cell thusly:

Dim tb As TextBox
tb = CType(e.Item.Cells(1).Controls(0), TextBox)

However! A DataGrid I created today will only work if I reference
Controls(1) rather than Controls(0):

Dim tb As TextBox
tb = CType(e.Item.Cells(1).Controls(1), TextBox)

Could someone please shed some light on how an attribute can "move
around" inside a control, in this case from position 0 to position 1?

I don't want them moving around after I'm done. :)
 
E

Elton Wang

The better way is to use

Dim tb As TextBox = CType(e.Item.FindControl(textbox_ID), TextBox)

HTH
 
D

davidfox789

Elton said:
The better way is to use

Dim tb As TextBox = CType(e.Item.FindControl(textbox_ID), TextBox)

HTH

Thanks for the reply.

I think I tried something like that before... I think I had the name in
quotes though (which may be similar to what you mean, if textbox_ID
above is a string... man I'm such a newbie at this) Anyhoo I will try
that in the future.

FWIW, is there a way to probe the contents of
e.Item.Cells(0).Controls­() programatically? (I tried QuickWatch -
there's so much detail, I don't know what I'm looking for.)

Maybe something like the following psedocode? ...

for each control in e.item.cells(0).controls()
display name and type
next
 
S

Sachin Saki

"(e-mail address removed)" ने लिखा:
I am new at this.. probably not proficient enough to even consider
myself a Newbie yet. :)

I have a DataGrid with Template columns. After the user edits a field
in the DataGrid and presses Update, the UpdateCommand code executes no
problem. However...

Normally I read the newly edited contents of a cell thusly:

Dim tb As TextBox
tb = CType(e.Item.Cells(1).Controls(0), TextBox)

However! A DataGrid I created today will only work if I reference
Controls(1) rather than Controls(0):

Dim tb As TextBox
tb = CType(e.Item.Cells(1).Controls(1), TextBox)

Could someone please shed some light on how an attribute can "move
around" inside a control, in this case from position 0 to position 1?

I don't want them moving around after I'm done. :)

Dim tb As TextBox
tb = CType(e.Item.Cells(1).Controls(1), TextBox)
Should try this think instead of above way
Dim txt as textbox
txt = CType(e.item.cell(1).FindControl(""id of textbox"),textbox)

This method works well for all cases.

Regards,
Sachin Saki
.NET Developer
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top