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

  • SEARCH
  • Home
  • 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 6912297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:04:27+00:00 2026-05-27T09:04:27+00:00

I want to ask how to get a text or value of a button

  • 0

I want to ask how to get a text or value of a button inside the gridview?
but i want to get the text value from this onrowcommand which use GridViewCommandEventArgs as its parameter.

as if im using onrowdatabound is (GridViewRowEventArgs), which makes it easy for me to get the button.text inside the gridview

string example = ((Button)e.Row.FindControl("btnStop")).Text;

I want to get the button.text to do an if else loop inside the onrowcommand.
Anyone know how?

 <asp:GridView ID="GridView1" runat="server" AllowPaging="True" CellPadding="2" CellSpacing="2"    HorizontalAlign="Center"   PageSize="5"  Width="133%" DataKeyNames="SurveyID" DataSourceID="SqlDataSource1" 
  AutoGenerateColumns="False" onrowcommand="stop_survey" 
       onrowdatabound="filter_select" onselectedindexchanging="selected" 
                                   >

code behind

 public void filter_select(object sender, GridViewRowEventArgs e)
 {
    if (e.Row.RowType == DataControlRowType.DataRow)
    {....
     ((Button)e.Row.FindControl("btnStop")).Text = "Start"; 
    }
 }

 public void stop_survey(object sender, GridViewCommandEventArgs e)
 {
      //i want to get the "btnStop" button text which is nested on the gridview.
 }

i want to get the btnStop text, as I want to have different sqlstatement depending on its text (eg. Start or Stop)
the problem is i cant do e.Row inside stop_survey.
Please guide me.

  • 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-27T09:04:27+00:00Added an answer on May 27, 2026 at 9:04 am

    Create a object of GridViewRow from refrence of command source row.

    GridViewRow row = (GridViewRow)((LinkButton)e.CommandSource).NamingContainer;
    

    But keep in mind that which type of object control is you are using to call event in above code is LinkButton. But if You Calling Rowcommand event from Simple Button then You need to Write this:

    GridViewRow row = (GridViewRow)((Button)e.CommandSource).NamingContainer;
    

    After Creating Row Object You can simply find any control from Gridview using rowindex.

    Label LabelEmail = (Label)GridView1.Rows[row.RowIndex].FindControl("LabelEmail");
    

    Finally You Can Access that Properties of that Control.

    LabelResult.Text = LabelEmail.Text; 
    

    Same as Above You can also find Datakeys of gridview using GridViewRow rowindex.

    int code = Convert.ToInt32(GridView1.DataKeys[row.RowIndex].Values[0].ToString()); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to insert some value from first and second foreach into database, but
Just want to ask can netbean IDE get connected to clearcase remote client server
want to ask user to input something but not want to wait forever. There
I want to ask if is there any faster method how to make this
Just want to ask if i can use Custom Validator in client side without
I want to ask a question about UITableViewCell. Apparently, this is what I want
This question is so basic that I'm almost embarrassed to ask it, but it's
I want to create a mechanism (in C#) where text from a QueryString is
actually i was opened question previously, but can't get answer what i exactly want,
I know that is a stupid question but i want to ask how i

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.