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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:55:56+00:00 2026-05-28T18:55:56+00:00

I am creating a gridview dynamically with a ButtonField and several BoundFields. ButtonField button

  • 0

I am creating a gridview dynamically with a ButtonField and several BoundFields. ButtonField button type is LinkButton. If i run it the buttonclick triggers a post back but rowCommand is not triggered. It is not triggered even if i use AutogenerateSelectButton. The event is dyanamically bound. Code As follows:

    protected void B_Search_Click(object sender, EventArgs e) //Search buttonclick that creates and displays the gridview
    {
        gd = getGridView(); //defines the gridview with columns and buttonfield

        gd.DataSource = executeAdvanceSearch(); //retrieves data from DB as Dataset
        gd.DataBind();

        gd.RowCommand += new GridViewCommandEventHandler(gdView_RowCommand); //Rowcommand event binding
        PlaceHolder1.Controls.Add(gd);
    }

    protected void gdView_RowCommand(object sender, GridViewCommandEventArgs e) //not getting triggered on postback
    {
        int index = Convert.ToInt32(e.CommandArgument);

        GridView gdView = (GridView)sender;

        if (e.CommandName == "IDClick")
        {
           //Do something
        }
    }


    private GridView getGridView()
    {
        GridView gdView = new GridView();
        gdView.AutoGenerateColumns = false;

        gdView.AutoGenerateSelectButton = true;

        string name;

        string[] field = ZGP.BLL.Search.getResultFormat(Convert.ToInt32(DDL_ResultView.SelectedValue), out name); //Ignore.  This jst gets columnNames

        if (field.Count() != 0)
        {
            gdView.Columns.Add(getSelectButton()); //Adds linkbutton

            foreach (string cName in field) //ignore. This adds columns.
                if (!String.IsNullOrEmpty(cName))
                {
                    gdView.Columns.Add(GV_DataColumn.getGridViewColumn((DataColumnName)Enum.Parse(typeof(DataColumnName), cName))); //Ignore. adds columns 
                }
        }

        return gdView;
    }

    private ButtonField getSelectButton()
    {
        ButtonField _bf = new ButtonField();
        _bf.ButtonType = ButtonType.Link;
        _bf.HeaderText = "ID";
        _bf.DataTextField = "ID";
        _bf.CommandName = "IDClick";
        return _bf;
    }

Thanks for the help.

  • 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-28T18:55:57+00:00Added an answer on May 28, 2026 at 6:55 pm

    You’ll need to create the grid view on each postback.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASPX page that is dynamically creating a gridview from a database
I am dynamically creating an Item template in a Gridview. TemplateColumn BtnTmpField = new
I am dynamically creating several gridviews depending on data in a DB. I generate
Greetings! I'm creating a User Control that will display data in a GridView control.
I am creating a GridView/DetailsView page. I have a grid that displays a bunch
I wrote a class similar to .NET GridView for android but my mind went
I am creating a GridView in a method like so: GridView gridView = new
I am creating a gridview that will be populated based upon a linq statement,
I'm having trouble creating a Gridview that can span 2 rows for each record.
I'm creating a dynamic gridview function which will bind different tables from DB into

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.