Handling OnDblClick Event of GridViewRow
I have a GridView that displays a list of names. On double-clicking a name, the name needs to be set in a textbox. This needs to happen w/o any postback
The RowCreated event of GridView should add a javascript event handler for the OnDblClick event as follows: ASPX Page:
<asp:TextBox ID="txtSearch" runat="server"/> <asp:GridView ID="gvMain" runat="server" AutoGenerateColumns="false" OnRowCreated="gvMain_RowCreated"> <Columns> <asp:BoundField HeaderText="Name" DataField="Name" /> </Columns> </asp:GridView>RowCreated Event Handler:
protected void gvMain_RowCreated(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Attributes.Add("OnDblClick", "setSearch(" + e.Row.RowIndex + ");"); } }The Javascript for the SetSearch() is below:
<script language="javascript" type="text/javascript"> function setSearch(row) { var tbl = document.getElementById("gvMain"); var txt = document.getElementById("txtSearch"); txt.value = tbl.rows[row+1].cells[0].innerText; } </script>Since GridView is rendered as table, the individual cell can be accessed as tbl.rows[rowIndex].cells[cellIndex].innerText
Posted by Vijay on 20-Sep-2009 05:00 PM
Category : ASP.NET GridView
Category : ASP.NET GridView



Hello Vijay,
I have read your forum at "http://forums.asp.net/p/1525995/3681124.aspx" i am looking for a share-point like feature. You can click Action => Edit as Datasheet. I need to implement this feature in ASP.Net web applicaiton. Please let me know if you have any solution workarround for this. my email id is: knisha77@gmail.com. Thank you in advance for your help.