Getting Text from DataGridItem object directly

Discussion in 'ASP .Net' started by tshad, Feb 23, 2005.

  1. tshad

    tshad Guest

    Is there a way to get the text from control, without actually defining it?

    For example, I have a DataGrid that has fields that are either Labels or
    Textboxes, depending on whether they are in edit mode or not.

    Dim answer as String
    Dim lblAnswer as Label = CType(oDataGridItem.FindControl("Answer"),Label)
    if lblAnswer = nothing then
    Dim txtAnswer as TextBox =
    CType(oDataGridItem.FindControl("Answer"),TextBox)
    answer = txtAnswer.text
    else
    answer = lblAnswer.text
    end if
    ' use answer for something

    Is there a way to get the text from an object in a DataGridItem, without
    having to set it to an object first?

    Thanks,

    Tom
     
    tshad, Feb 23, 2005
    #1
    1. Advertising

  2. tshad

    MasterGaurav Guest

    Are you using ASP.Net 1.1? If so, the best idea is to definte a
    Protected control:

    Protected Dim Answer as Label
    ' The name, Answer, should match what is given in the ASPX file.

    Then, directly use:

    Answer.Text


    In ASP.Net 2.0, you can make use of Partial Classes.



    --
    Cheers,
    Gaurav Vaish
    http://www.mastergaurav.org
    http://mastergaurav.blogspot.com
    --------------------------------
     
    MasterGaurav, Feb 24, 2005
    #2
    1. Advertising

  3. tshad

    MasterGaurav Guest

    MasterGaurav, Feb 24, 2005
    #3
  4. Tom,

    Define both of them but make only one visible at the time. On entering/exit
    editing mode, toggle visibility and copy text between the controls.

    Eliyahu

    "tshad" <> wrote in message
    news:...
    > Is there a way to get the text from control, without actually defining it?
    >
    > For example, I have a DataGrid that has fields that are either Labels or
    > Textboxes, depending on whether they are in edit mode or not.
    >
    > Dim answer as String
    > Dim lblAnswer as Label = CType(oDataGridItem.FindControl("Answer"),Label)
    > if lblAnswer = nothing then
    > Dim txtAnswer as TextBox =
    > CType(oDataGridItem.FindControl("Answer"),TextBox)
    > answer = txtAnswer.text
    > else
    > answer = lblAnswer.text
    > end if
    > ' use answer for something
    >
    > Is there a way to get the text from an object in a DataGridItem, without
    > having to set it to an object first?
    >
    > Thanks,
    >
    > Tom
    >
    >
     
    Eliyahu Goldin, Feb 24, 2005
    #4
  5. Hello
    you also need the index of data Grid item in which you are going to find
    that control .
    you dont have need to declare the control any where
    just assign it an id and use it to finding control ,

    Regards
    Malik Asif
    "tshad" <> wrote in message
    news:...
    > Is there a way to get the text from control, without actually defining it?
    >
    > For example, I have a DataGrid that has fields that are either Labels or
    > Textboxes, depending on whether they are in edit mode or not.
    >
    > Dim answer as String
    > Dim lblAnswer as Label = CType(oDataGridItem.FindControl("Answer"),Label)
    > if lblAnswer = nothing then
    > Dim txtAnswer as TextBox =
    > CType(oDataGridItem.FindControl("Answer"),TextBox)
    > answer = txtAnswer.text
    > else
    > answer = lblAnswer.text
    > end if
    > ' use answer for something
    >
    > Is there a way to get the text from an object in a DataGridItem, without
    > having to set it to an object first?
    >
    > Thanks,
    >
    > Tom
    >
    >
     
    Malik Asif Joyia, Feb 24, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul Perot
    Replies:
    0
    Views:
    396
    Paul Perot
    Dec 12, 2003
  2. Richard Loupatty

    Visibility of selectedindex of a datagriditem

    Richard Loupatty, Jan 12, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    804
    Richard Loupatty
    Jan 12, 2004
  3. tshad
    Replies:
    0
    Views:
    278
    tshad
    Oct 31, 2009
  4. Samuel Chowdhuri
    Replies:
    1
    Views:
    329
    Alvin Bruney
    Oct 20, 2003
  5. Daniel Berger
    Replies:
    1
    Views:
    100
    Kent Sibilev
    Jun 9, 2005
Loading...

Share This Page