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 6233641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:20:13+00:00 2026-05-24T10:20:13+00:00

<asp:GridView ID=gvGrid runat=server AutoGenerateColumns=False DataSourceID=dsDataSource AllowPaging=True PageSize=20 > <Columns> <asp:BoundField DataField=Field1 HeaderText=Field1 SortExpression=Field1 />

  • 0
    <asp:GridView ID="gvGrid" runat="server" AutoGenerateColumns="False" 
        DataSourceID="dsDataSource" AllowPaging="True" PageSize="20" >
        <Columns>
            <asp:BoundField DataField="Field1" HeaderText="Field1" 
                SortExpression="Field1" />
            <asp:BoundField DataField="Field2" HeaderText="Field2" 
                SortExpression="Field2" />
            <asp:TemplateField HeaderText="TemplateField1">
                <ItemTemplate>
                    <asp:Label id="lblComments" runat="server" Text=" i use a function to compute"></asp:Label>
                </ItemTemplate> 
            </asp:TemplateField>

          <asp:CommandField ShowSelectButton="True" SelectText="Complete" HeaderText ="Status" />

            <asp:TemplateField HeaderText="Action">
                <ItemTemplate>
                       <asp:Button ID="btnComplete" runat="server" Text="Complete" onclick="btnComplete_Click"/>
                    <asp:Button ID="btnAddComment" runat="server" Text="Add Comment" onclick="btnAddComment_Click" />    
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>

protected void btnComplete_Click(object sender, EventArgs e) 
{

    String Field1 = gvGrid.SelectedRow.Cells[1].Text; // throws an error at runtime

   //I want to be able to access the row data do some computation and then be able to insert it into the database 
// Reason why I am trying to use it as a template field instead of a commandfield is because I want to make it not visible when it meets certain condition. 
}

Also, it would be great if you could let me know a better way to do it, maybe using the command field and if there is a way to toggle its visibility. I don’t mind using LinkButton either.

  • 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-24T10:20:14+00:00Added an answer on May 24, 2026 at 10:20 am

    You can do it like this:

    protected void btnComplete_Click(object sender, EventArgs e)    
    {  
         Button btn = (Button)sender;
         GridViewRow gvRow = (GridViewRow)btn.Parent.Parent;
    
         //Alternatively you could use NamingContainer
         //GridViewRow gvRow = (GridViewRow)btn.NamingContainer;
    
         Label lblComments = (Label)gvRow.FindControl("lblComments");
    
         // lblComments.Text ...whatever you wanted to do
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

<asp:GridView ID=GridView2 runat=server AllowPaging=True AllowSorting=True AutoGenerateColumns=False DataSourceID=LinqDataSource1> <Columns> <asp:BoundField DataField=UserName HeaderText=User Name ReadOnly=True SortExpression=UserName
<asp:GridView ID=GridView3 runat=server Width=100% DataSourceID=SDSAllowPaging=True AutoGenerateColumns=False > <Columns> <asp:BoundField DataField=Hint HeaderText=textSortExpression=Hint /> <asp:BoundField DataField=Visi
I have the following gridview: <asp:GridView ID=gdvReport runat=server AutoGenerateColumns=False DataSourceID=sdseport> <Columns> <asp:BoundField DataField=Phone HeaderText=Phone
i have the following gridview <asp:GridView ID=GridView3 runat=server AllowPaging=True AllowSorting=True AutoGenerateColumns=False DataKeyNames=ID DataSourceID=CommentsDataSource> <Columns>
<asp:GridView ID=GridView2 runat=server AllowPaging=True AutoGenerateColumns=False DataSourceID=opendiarysource Font-Size=Small style=font-size: 8pt; border-top-style: solid; border-right-style: solid; border-left-style:
Here is my ASP code: <asp:GridView ID=WagerTable runat=server AutoGenerateColumns=False CssClass=basix > <columns> <asp:BoundField DataField=GameName
I have a GridView : <asp:GridView ID=GridView1 runat=server AllowPaging=True GridLines=None HorizontalAlign=Left AutoGenerateColumns=False DataSourceID=SqlDataSource1 onrowcommand=GridView1_RowCommand1>
<asp:GridView Width=700 ID=gridInboxMessage runat=server DataSourceID=LinqDataSource1> <Columns> <asp:BoundField DataField=Row Visible=false HeaderStyle-Width=10 HeaderText=row ReadOnly=True SortExpression=Row />
I have a simple gridview <asp:GridView ID=GridView1 runat=server DataKeyNames=OriginatorID AutoGenerateColumns=False AllowPaging=True OnPageIndexChanging=GridView1_PageIndexChanging PageSize=5 OnPreRender=GridView1_PreRender>
i have a asp.net webpage with a GridView <asp:GridView ID=grid_view runat=server AllowPaging=True AutoGenerateColumns=False BackColor=White

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.