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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:31:47+00:00 2026-05-27T16:31:47+00:00

I am having a gridview with some columns and a template field column that

  • 0

I am having a gridview with some columns and a template field column that contains a button and I want to call a procedure on button click, however I want to pass a value of a column to the procedure but I am getting an error, here is the action listener of the button: (column name in the gridview is team_ID)
error: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
error line: int team_ID = Convert.ToInt32(Eval(“team_ID”));

protected void Button1_Click(object sender, EventArgs e)
    {
        string connStr = ConfigurationManager.ConnectionStrings["MyDbConn"].ToString();
        SqlConnection conn = new SqlConnection(connStr);

        SqlCommand cmd = new SqlCommand("join_team", conn);
        cmd.CommandType = CommandType.StoredProcedure;
        int team_ID = Convert.ToInt32(Eval("team_ID"));
        string email = Session["email"].ToString();
        cmd.Parameters.Add(new SqlParameter("@team_ID", team_ID));
        cmd.Parameters.Add(new SqlParameter("@myemail", email));
        conn.Open();
        cmd.ExecuteNonQuery();
        conn.Close();

    }
  • 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-27T16:31:48+00:00Added an answer on May 27, 2026 at 4:31 pm

    First, to handle a button what was clicked in an TemplateField, you’ll want to subscribe to the RowCommand method:

    <asp:GridView runat="server" ID="gv" OnRowCommand="yourMethod">
    

    You can have multiple buttons in your grid and surmise which caused the click with the CommandName property. The code below shows this, as well as how to get the row of the button that was clicked, and retrieve other controls from that row so you can get their values.

    <asp:TemplateField>
          <ItemTemplate>
                <asp:Button CommandName="yourButtonName" runat="server" />
    

    Code Behind

    protected void yourMethod(object sender, GridViewCommandEventArgs e) {
        if (e.CommandName == "yourButtonName") {
    
            GridViewRow row = (GridViewRow)(((Button)e.CommandSource).NamingContainer);
    
            TextBox someTextBox = row.FindControl("tb") as TextBox;
            string textValue = someTextBox.Text;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having a Gridview.In that ther are 2 columns,like Image and Status. In
Having the GridView client control ID, I would like to get some ideas on
I having issues exporting a GridView to Excel for some reason. I have two
I've created a Gridview control that pulls some data from my database, but doesn't
Having some problems with a solution that apparently works: <script type=text/javascript > //following code
I have a GridView that allows editing the values in every column, in every
I'm having some trouble with editing a gridview row's background color when Editing it.
im having some wierd issue with my GridView. Basically, im trying to run a
I having the page in that i have the gridview and page index changing
I am having editable Gridview with column named Country which has so long listing.

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.