Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1052035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:01:42+00:00 2026-05-16T17:01:42+00:00

It has been so long since I have coded a page in VB. For

  • 0

It has been so long since I have coded a page in VB. For the life of me I just cannot remember how to do this.

I have a GridView on an ASP page. Each row has a comment ImageButton. I already have the gridview and text box wrapped in a UpdatePanel. The gridview shows all of the correct information. I just need to add some code to populate the text box with the comment when a user clicks on that row’s ImageButton.

The comments are stored in SQL 2005 DB if that makes a difference. Should I shove the comments inside a hidden field of the gridview or is there a function that will allow me to query the db for that specific comment.

End goal would be to not refresh the page if possible.

Your help is greatly appreciated to help me get over this writer’s block!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T17:01:42+00:00Added an answer on May 16, 2026 at 5:01 pm

    OK, you could do this either way, with a HiddenField or by looking up in the DB.

    HiddenField

    In the ItemTemplate that contains the ImageButton, add CommandName and CommandArgument attributes to the ImageButton, and a HiddenField that is bound to the comment field from the database:

    <asp:TemplateField HeaderText="Comment">
        <ItemTemplate>
            <asp:ImageButton ID="btnComment" runat="server" ImageUrl="images/comment.gif" CommandName="SelectComment" CommandArgument='<%# Container.DataItemIndex %>' />
            <asp:HiddenField runat="server" id="CommentHiddenField" Value='<%# Eval("Comment") %>' />
        </ItemTemplate>
    </asp:TemplateField>
    

    In the code-behind, add a method for handling the RowCommand event for the GridView:

    Private Sub Gridview2_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles Gridview2.RowCommand
    
        Dim rowIndex As Integer
        Dim commentHiddenField As HiddenField
    
        If e.CommandName = "SelectComment" Then
            rowIndex = Integer.Parse(e.CommandArgument.ToString)
    
            commentHiddenField = DirectCast(Gridview1.Rows(rowIndex).Cells(5).FindControl("CommentHiddenField"), HiddenField)
    
            txtComments.Text = commentHiddenField.Value
        End If
    
    End Sub
    

    DB Lookup

    Add the attributes to the ImageButton:

    <asp:TemplateField HeaderText="Comment">
        <ItemTemplate>
            <asp:ImageButton ID="btnComment" runat="server" ImageUrl="images/comment.gif" CommandName="SelectComment" CommandArgument='<%# Container.DataItemIndex %>' />
        </ItemTemplate>
    </asp:TemplateField>
    

    In the code-behind, add a method for handling the RowCommand event for the GridView:

    Private Sub Gridview2_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles Gridview2.RowCommand
    
        Dim rowIndex As Integer
        Dim key As String
    
        rowIndex = Integer.Parse(e.CommandArgument.ToString)
    
        key = Gridview1.DataKeys(rowIndex).Value.ToString
    
        txtComments.Text = GetCommentFromDB(key)
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It has been a long time since I have written XSL, I have this
It has been a long time since I used java and I have run
I have this classic ASP site which has been working fine until we updated
It has been way to long since I have been involved in VB so
Does Windows XP (and up) store how long it has been... ...since the system
This has been pending for a long time in my list now. In brief
This problem has been bugging me for a long time. For example, the code
This question has been bugging me for a long time now but essentially I'm
This question has been puzzling me for a long time now. I come from
I have a big question that has been puzzling me for a long time

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.