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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:37:28+00:00 2026-06-16T04:37:28+00:00

I want my GridView Rows to fire the SelectedIndexChanged event when I click on

  • 0

I want my GridView Rows to fire the SelectedIndexChanged event when I click on them.

I tried the following in code behind:

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowIndex != -1)
        {
            e.Row.Attributes.Add("onMouseOver", "Highlight(this)");
            e.Row.Attributes.Add("onMouseOut", "UnHighlight(this)");

            e.Row.Attributes.Add("onClick", String.Format("javascript:__doPostBack('GridView1','Select${0}')", e.Row.RowIndex));
        }
    }

Postback happens when I click on a row, but it doesn’t fires SelectedIndexChanged. In the Page_Load I get the arguments from the request:

        if (IsPostBack)
        {
            object obTarget = this.Request.Form["__EVENTTARGET"]; //GridView1
            object obArg = this.Request.Form["__EVENTARGUMENT"]; //Select$4
        }

I think that SelectedIndexChanged would have to be raised, or do i have a misunderstanding on this?

  • 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-06-16T04:37:29+00:00Added an answer on June 16, 2026 at 4:37 am

    You are probably rebinding the GridView to its DataSource on postback. You should do that only if(!IsPostBack) (with enabled ViewState), otherwise events aren’t triggered.

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GridView1.DatSource = GetGataSource();
            GridView1.DataBind();
        }
    }
    

    You should also register event handler on every postback but RowDataBound is only called on databinding. So use RowCreated instead.

    It’s also better to use Page.GetPostBackClientHyperlink instead of hardcoding the javascript function.

    e.Row.Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink((GridView)sender, "Select$" & e.Row.RowIndex) 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an onclientclick event going on in the gridview rows, but I want
I want to use CSS to format my GridView rows. I've set up my
Have a gridview control which will show X amount of rows. I want to
I want to make my gridview rows selectable. I don't like the idea of
Is there a way to add a RowClick Event to Gridview Rows without adding
i want to set gridview column itemstyle wrap to false in c# code. how
I have a GridView with an EntityDataSource. I want to filter the rows at
I have a gridview, where i can add/delete rows. I dont want to give
I have a gridview and I want to add rows in it dynamically. I
I want to delete rows in my gridview with the delete button on keyboard.

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.