Click here to Skip to main content
15,883,901 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
HI
Can any one tell me how to fire client side event on selection of gridview row with out using other controls , none of my search brought me result.


Thank you
Posted
v3

I don't think the gridview control has any client side events.

... but, as it renders an html table, you can create and attach your own.

Here is an example, which should get you started:
http://weblogs.asp.net/andrewrea/archive/2008/08/04/gridview-row-click-selection-via-clientside-code.aspx[^]

... hope it helps.
 
Share this answer
 
Yes ofcourse. Try like below. Use RowDataBound Event.
C#
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    //check the item being bound is actually a DataRow, if it is,
    //wire up the required html events and attach the relevant JavaScripts
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        e.Row.Attributes["onclick"] =
            "javascript:gridRowOnclick(this);";
    }
}

Then write JavaScript function gridRowOnclick.
JavaScript
function gridRowOnclick(element)
{
    alert("GridView clicked");
}
 
Share this answer
 
Comments
Karthik_Mahalingam 8-Jan-14 9:47am    
5 good.
Tadit, i thought of posting the same, but after seeing your solution.i stopped. :-)
:D Thanks a lot Karthik. :)
JoCodes 8-Jan-14 10:30am    
Good one Tadit:)
Thanks a lot JoCodes. :) Up voting would make me feel happier. :P :D
JoCodes 8-Jan-14 22:24pm    
Done. :)
if posback happens you need to rebind the data to gridview again. many limitations
 
Share this answer
 
Comments
CHill60 14-Jul-20 8:24am    
This is not a solution to this question

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900