Accessing gridview controls

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pieandpeas
    New Member
    • Sep 2007
    • 43

    #1

    Accessing gridview controls

    I've got a textbox in a gridview, when i reference this textbox in my vb code i get - Name 'tbValue' is not declared. However, if i bring this textbox out of my gridview and place it somewhere else on the page it can be assigned things via the code.

    my question is, how do i get to access the values of a textbox when it is used in a gridview to display information?
  • nateraaaa
    Recognized Expert Contributor
    • May 2007
    • 664

    #2
    Originally posted by pieandpeas
    I've got a textbox in a gridview, when i reference this textbox in my vb code i get - Name 'tbValue' is not declared. However, if i bring this textbox out of my gridview and place it somewhere else on the page it can be assigned things via the code.

    my question is, how do i get to access the values of a textbox when it is used in a gridview to display information?
    You can access the textbox by using the findcontrol method on the gridview.

    for example

    Code:
    Dim TextBox tb = (TextBox)gridview1.FindControl("tbValue")
    I mostly use C# so this may not be the correct syntax for VB but it should be something like this.

    Nathan

    Comment

    • pieandpeas
      New Member
      • Sep 2007
      • 43

      #3
      Originally posted by nateraaaa
      You can access the textbox by using the findcontrol method on the gridview.

      for example

      Code:
      Dim TextBox tb = (TextBox)gridview1.FindControl("tbValue")
      I mostly use C# so this may not be the correct syntax for VB but it should be something like this.

      Nathan
      Thanks, please could you give me an example of this code in use (does it need a loop, if i only want to access the textbox on a certain line in the gridview)?, as i'm not sure how to actually use this code in my vb code. Thanks :)

      Comment

      • nateraaaa
        Recognized Expert Contributor
        • May 2007
        • 664

        #4
        Have a look at this link I think it should help.

        Nathan

        Comment

        Working...