Reputation: 872
I have an onclientclick event going on in the gridview rows, but I want to call a serverside method when I click anywhere on a row. How can I accomplish this WITHOUT the use of an extra column + select button + onselectedindexchanged?
Thank you
Upvotes: 0
Views: 1362
Reputation: 43097
Add a button with a server side button click handler. If you don't want it visible, use css to hide it (display: none;
). You can then wire up a client side click handler on <tr>
for your GridView table and have it trigger the button's click event.
Button in your grid view:
<asp:LinkButton runat="server" CssClass="row-button" OnClick="ServerSideClickHandler" Text="Click me"/>
Css to hide your button:
.row-button { display: none; }
Client side handler using jQuery:
$(document).ready(function() {
$("tr").click(function() {
$(".row-button", this).click();
});
});
Upvotes: 1
Reputation: 1467
I'm not sure what exactly you are trying to accomplish here but I don't think you need to use a grid view event at all. I'm assuming you are going to use some javascript to handle the click anywhere on a row correct? You could put an asp link button in one of the existing columns using CSS to hide it so it's not visible. Then have your javascript click the button. Then the link button can have it's own backing method like normal.
You might want to have the link button do a command instead of an onClick so you can pass a command argument of the row index or data item Id.
Would that handle your situation?
Upvotes: 2
Reputation: 438
I dont think there is any event you can use as it is.
You may want to Write a custom function in javascript/JQuery to post to your URL.
Upvotes: 1