DetailsView & TextBox (C#)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • G

    #1

    DetailsView & TextBox (C#)

    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.

  • Jani Järvinen [MVP]

    #2
    Re: DetailsView & TextBox (C#)

    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.R ows[2]; // third row
    TextBox myTextBox = (TextBox)row.Ce lls[1].Controls[0]; // text box in second
    cell
    myTextBox.Text = ...
    ----------

    Hope this helps!

    --
    Regards,

    Mr. Jani Järvinen
    C# MVP
    Helsinki, Finland
    janij@removethi s.dystopia.fi



    Comment

    Working...