• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 613
  • Last Modified:

DoubleClick Event DataGrid Select Row

I have a datagrid that is bound to a dataset table. I would like to implement a select feature where the user may doubleclick anywhere in the row to select that row of the datagrid. I would like the selected row to then populate some text boxes. I understand this is possible with a select button but I do not want to use this method.

When I try to use the DoubleClick event of the datagrid I get the following error:  BC30590: Event 'DoubleClick' cannot be found

Heres an extract of my code:

   Sub DataGrid_DoubleClick(sender as Object, e As EventArgs) Handles MyDataGrid.DoubleClick
      'doubleclick processing
   End Sub

 <asp:DataGrid id="MyDataGrid" runat="server"
         BorderColor="black" GridLines="Vertical"
         cellpadding="4" cellspacing="0"
         AutogenerateColumns = "True"

Could someone please give me an example. I have tried everything. I believe its possible to use the double click event but not sure how to set up. Thanks
  • 3
  • 2
1 Solution
double click is not supported by datagrid and cannot be used the way u r planning .. there is no postback that occurs when u double click a datagrid  and u cannot write event handlers for that .. atleast not in a web application ..

HI i have the code for the single click anywhere on row to select the row

it is as follows

write the following code in the datagrid_ItemCreated

                  if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.SelectedItem)
                        e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='beige';this.style.cursor='hand'");
                        e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='white';");
                        string jScript = "javascript:__doPostBack('" + "Datagrid$" + "_ctl" + (e.Item.ItemIndex + 2) + "$_ctl0','')";
                        e.Item.Attributes.Add("onclick", jScript + ";SelectMultipleRows()");//(" + e.Item.ItemIndex +")");
datagrid is the name of the datagrid
also u might have to change the value 2 in (e.Item.ItemIndex + 2) depending on ur grid (if u have fotter then it wil be 3)
Note-Please check the backcolor of ur grid on the mouse over and mouseout event.

then u can handle the select command in the Datagrid_ItemCommand which add the value to the textbox from the grid
as per ur requirment

 e.Item.Attributes.Add("onclick", jScript + ";SelectMultipleRows()");//(" + e.Item.ItemIndex +")");

 please change this line  to

  e.Item.Attributes.Add("onclick", jScript)
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

dbknAuthor Commented:
Thanks SandeepRR.

This seems to only be working for the header row at top. I would like this functionality to occur on each cell. Any suggestions?
Hi just giving the complete steps to be followed for the solution

Add one select button to datagrid and that u can hide as per ur requirment.

now Add following code to ur Datagridname_ItemCreated method

if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.SelectedItem)
                                        e.Item.Attributes.Add("onmouseover", "this.style.cursor='hand'");
                                        string jScript = "javascript:__doPostBack('" + this.UniqueID.ToString() +"$dgSearchResult$" + "_ctl" + (e.Item.ItemIndex + 3) + "$LinkButton1','')";
                    e.Item.Attributes.Add("onclick", jScript);

where dgSearchResult is name of my datagrid

the "inkButton1"is my select button name, now if u dont know the link button name then one thing u can do is run the application with select button visible and just go over to select button and see the script in the status bar of Internet Explorer.(this is what we have to call on the row click event and thi string goes in string jscript)

And about the (e.Item.ItemIndex + 3) this u might haev to change to (e.Item.ItemIndex + 2) as per ur requirment.

And about the (e.Item.ItemIndex + 3) this u might haev to change to (e.Item.ItemIndex + 2) as per ur requirment.

hopefully it works for u.

but ur requirement was not just to select a row, but to submit the page on double click .. if u plan to do this using a single click i.e. submit a page on selection of a row, there would be a postback for every click in ur grid .. i assume this would not be too user friendly .. do think about it ..

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now