Read value from a Textbox in a grid view.

Discussion in 'ASP .Net Web Controls' started by Felix Wafytech, May 23, 2007.

  1. Hello,

    I have a grid view with a template column and a button column. This template
    field contains a textbox in the Item Template tab. Entering a value in the
    text box and clicking on the button in that row should retrieve the value
    entered and insert it into another gridview. The problem here is, I'm unable
    to retrieve the value entered in the text box on the button click event. Can
    someone help me on how I could retrieve the value in the text box?

    Note that the grid is not in edit mode. There are other columns in the grid
    that display the data in read-only mode. BTW, I do not want to use a command
    button to edit and update data because I do not want to update the database
    here. I just need to retrieve the value entered by the user in text box when
    the button in that row is clicked.

    Thanks in advance for all the help. Your help is very much appreciated.

    Thanks,
    Felix.J
    Felix Wafytech, May 23, 2007
    #1
    1. Advertising

  2. Felix Wafytech

    vMike Guest

    "Felix Wafytech" <> wrote in message
    news:...
    > Hello,
    >
    > I have a grid view with a template column and a button column. This

    template
    > field contains a textbox in the Item Template tab. Entering a value in the
    > text box and clicking on the button in that row should retrieve the value
    > entered and insert it into another gridview. The problem here is, I'm

    unable
    > to retrieve the value entered in the text box on the button click event.

    Can
    > someone help me on how I could retrieve the value in the text box?
    >
    > Note that the grid is not in edit mode. There are other columns in the

    grid
    > that display the data in read-only mode. BTW, I do not want to use a

    command
    > button to edit and update data because I do not want to update the

    database
    > here. I just need to retrieve the value entered by the user in text box

    when
    > the button in that row is clicked.
    >
    > Thanks in advance for all the help. Your help is very much appreciated.
    >
    > Thanks,
    > Felix.J
    >
    >

    You would do something along the following lines. Each "submit" button will
    have an ID which is the id you specify plus what .net adds to the name.
    Your text boxes will do the same. So the id of the button and the id of the
    text box will have the same "stuff" added to them except for the base name.
    With that in mind you would do something like the following

    Sub ButtonSubmit_Click(sender as object, e as eventargs)
    dim strTextBoxID as string
    dim tbox1 as textbox
    dim buttton1 as button
    dim strButton1ID as string
    button1 = DirectCast(sender,textbox)
    strButton1ID = button1.uniqueid
    strTextBoxID =
    strSender1.replace("idbasenamebforbutton","idbasenamefortextbox")
    tbox1 = ctype(Page.findcontrol(strTextBoxID),textbox)
    yourtextintextbox1 = tbox1.text

    End Sub
    vMike, May 23, 2007
    #2
    1. Advertising

  3. Felix Wafytech

    vMike Guest

    Niote


    strSender1 should be strButton1ID sorry. I would snipping code

    Mike
    vMike, May 23, 2007
    #3
  4. Felix Wafytech

    vMike Guest

    Having a bad day... button1 = DirectCast(sender,textbox)
    should read button1 = DirectCast(sender,button)
    vMike, May 23, 2007
    #4
  5. Hi Felix,

    I think you can use databinding to bind the rowIndex of each row to the
    Button's CommandArgument(or Command) property so that you can read it
    later. Then, in button's click event, you can get the current Row(where the
    button in) through the CommandArgument(or Command ) propety you set early
    and use FindControl to locate the certain controls you want in Gridview Row
    or Column. How do you think?

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead



    ==================================================

    Get notification to my posts through email? Please refer to
    http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    ications.



    Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    where an initial response from the community or a Microsoft Support
    Engineer within 1 business day is acceptable. Please note that each follow
    up response may take approximately 2 business days as the support
    professional working with you may need further investigation to reach the
    most efficient resolution. The offering is not appropriate for situations
    that require urgent, real-time or phone-based interactions or complex
    project analysis and dump analysis issues. Issues of this nature are best
    handled working with a dedicated Microsoft Support Engineer by contacting
    Microsoft Customer Support Services (CSS) at
    http://msdn.microsoft.com/subscriptions/support/default.aspx.

    ==================================================



    This posting is provided "AS IS" with no warranties, and confers no rights.
    Steven Cheng[MSFT], May 24, 2007
    #5
  6. Felix Wafytech

    vMike Guest

    "Steven Cheng[MSFT]" <> wrote in message
    news:...
    > Hi Felix,
    >
    > I think you can use databinding to bind the rowIndex of each row to the
    > Button's CommandArgument(or Command) property so that you can read it
    > later. Then, in button's click event, you can get the current Row(where
    > the
    > button in) through the CommandArgument(or Command ) propety you set early
    > and use FindControl to locate the certain controls you want in Gridview
    > Row
    > or Column. How do you think?
    >
    > Sincerely,
    >
    > Steven Cheng
    >
    > Microsoft MSDN Online Support Lead
    >
    >

    Agreed, something like this would work too. This is an imagebutton snip
    using an earlier set command argument.

    Sub Unlock_Click(sender as object, e as ImageClickEventArgs)
    dim ctl as imagebutton = ctype(Sender, imagebutton)
    dim intID as int32 = ctype(ctl.commandargument, int32)
    dim intOffset as int32 = (BlogGrid1.PageIndex) * BlogGrid1.PageSize
    Dim row As GridViewRow = BlogGrid1.Rows(intID-intOffset)
    dim ctl2 as textbox = ctype(row.findcontrol("Title1"),textbox)

    Mike
    vMike, May 24, 2007
    #6
    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. =?Utf-8?B?QXNzYW5LaGFuIElzbWFpbA==?=

    How to transfer a value from an Invisible Grid to an visible Grid

    =?Utf-8?B?QXNzYW5LaGFuIElzbWFpbA==?=, Oct 13, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    467
    =?Utf-8?B?QXNzYW5LaGFuIElzbWFpbA==?=
    Oct 17, 2005
  2. Luqman
    Replies:
    2
    Views:
    3,813
    Luqman
    Feb 1, 2006
  3. CK

    Grid View Row Value

    CK, Oct 31, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    554
    Eliyahu Goldin
    Nov 1, 2006
  4. wahtnamas
    Replies:
    0
    Views:
    894
    wahtnamas
    May 1, 2009
  5. Parthiv Joshi
    Replies:
    1
    Views:
    665
    Samuel L Matzen
    Jul 6, 2004
Loading...

Share This Page