DetailsView & TextBox (C#)

  • Thread starter Thread starter G
  • Start date Start date
G

G

Hello,

I have a detailsview on page, called DetailsView1. I also have an
ItemTemplate TextBox called PaymentStatus.

I want to from CODE BEHIND update the text of PaymentStatus but I am unable
to reference this object, and I have tried for hours to use FindControl to
no real progress.

Anyone able to help?

Regards,

Gary.
 
Hello Gary,
I want to from CODE BEHIND update the text of PaymentStatus but I am
unable to reference this object, and I have tried for hours to use
FindControl to no real progress.

I suggest that you use the Rows property (whics is a collection) to access
the rows (and controls thereafter) in your DetailsView component instead of
using FindControl. FindControl should work, but the problem is that many
component names have dynamically created names, and might not be what you
expect.

Instead, try using the Rows property with an index. For example, you could
use code similar to this:

----------
DetailsViewRow row = MyDetailsView.Rows[2]; // third row
TextBox myTextBox = (TextBox)row.Cells[1].Controls[0]; // text box in second
cell
myTextBox.Text = ...
----------

Hope this helps!

--
Regards,

Mr. Jani Järvinen
C# MVP
Helsinki, Finland
(e-mail address removed)
http://www.saunalahti.fi/janij/
 

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

Back
Top