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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:07:54+00:00 2026-05-30T12:07:54+00:00

I have a gridview that fill it with some data. <asp:GridView ID=GridView1 runat=server ClientIDMode=Static>

  • 0

I have a gridview that fill it with some data.

<asp:GridView ID="GridView1" runat="server" ClientIDMode="Static">
</asp:GridView>

code:

    if (!IsPostBack)
    {
        using (DataClassesDataContext dc = new DataClassesDataContext())
        {
            GridView1.DataSource = dc.Regions.ToList();
            GridView1.DataBind();
        }
    }

I want when I clicked on TH section an alert showed.I wrote this code:

   <script type="text/javascript">
    $('#GridView1 th').on("click", function () {
        alert("nima");
     });   
</script>

but it doesc not work.where is my mistake?

thanks


Edit 1)
I Edit main question and add ' for selector.I forgot to type that.
the problem is when I write this code it works.I want to know on does not work:

$('body').live('click','#GridView1 th', function () {
        alert("hello");
    });  
  • 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-30T12:07:55+00:00Added an answer on May 30, 2026 at 12:07 pm

    are you sure you’re writting $(#GridView1 th)? should be at least $('#GridView1 th')… and check the View Source to see if the correct ID as if it’s nested in other ASP.NET control will never be GridView1…

    to be safe in any ASP.NET control you should use the ClientID property, so you can always write:

    <script type="text/javascript">
        var grid = '<%= GridView1.ClientID %>';
        $("#" + grid + " th").on("click", function () {
            alert("hello");
         });   
    </script>
    

    And verify in your source code if you actually have a Table Header <th> as I know It was optional in the GridView earlier days…

    From your code, you just forgot that the script will run as soon is it on the page and mostly when the table code is not even there…

    change this:

    <script src="Scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $('#GridView1 th').on('click', function () {
            alert("nima");
        });  
    </script>
    

    into this

    <script src="Scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function() {
           $('#GridView1 th').on('click', function () {
              alert("nima");
           });  
        });
    </script>
    

    or simply append your script code at the end of the page, so when the browser reach that line, all the others are already rendered and available to the DOM.

    Here is a Live Example of your code: http://jsbin.com/etamug/edit#javascript,html simply click the Render button to see everything up and running…

    I have used $(function() {}); as a shortcut, but the original method is the one I have specified in this answer.

    You can find more information regarding $(document).ready() in jQuery website

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

Sidebar

Related Questions

I have a gridview that is databound in the code-behind using a stored procedure.
i have to fill a gridview with a dbcoommand. The code that i have
I have a gridview that is using a LinqDataSource for it's datasource. I've added
I have a gridview that I have added a checkbox column using a templatefield
I have two tables I am using to fill a gridview. The tables have
I picked up some code that is building a Gridview with a SQLDataAdapter. One
Hey guys, I have an application that I want to display some data from
I've been using some code very similar to the following to populate a gridview
i have an gridview that retrieves the data via a datatable like this: protected
I have an android gridview which i'm using some custom scrolling going on in,

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.