0

I am using Asp.Net/C# in my project , in one of my pages I have a GridView and I am using the following line to handle row click

e.Row.Attributes.Add("onclick", "location='Default.aspx?id=" + e.Row.Cells[0].Text + "'");

This is working fine , however I have a requirement to call a jquery function which displays a popup , here is the function

function ShowDialog(modal) {
        $("#popupmask").show();
        $("#popup").fadeIn(300);

        if (modal) {
            $("#popupmask").unbind("click");
        }
        else {
            $("#popupmask").click(function(e) {
                HideDialog();
            });
        }
    }

Can anyone suggest me how can I call jquery function on row click of Asp.Net Gridview Thanks

1

2 Answers 2

2

Try something like this:

$("#<%=GridView1.ClientID%> tr").click(function(){
    alert("Row clicked");
});
Sign up to request clarification or add additional context in comments.

Comments

0

There are many ways to do that i am showing you one simple way to do that.

First you need to wirte these lines in your asp.net Grid code.

<RowStyle CssClass="myrow" />
<AlternatingRowStyle CssClass="myrow" />

then your grid looke like this.

<asp:GridView ID="GridView1" runat="server">
   <RowStyle CssClass="one" />
   <AlternatingRowStyle CssClass="one" />

   </asp:GridView>


<script >
    $(function () {
        $('.myrow').click(function () {
           //below line get 1st td of your selected tr of the grid
            console.log($(this).children().eq(0));

            alert('clicked ');
        });
    });

</script>

2 Comments

I believe you don't need to specify the AlternatingRowStyle. I think this just overrides the RowStyle when applied.
Thats better to use alternateRowStyle . . .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.