DoubleClick Event DataGrid Select Row

Posted on 2006-05-30
Last Modified: 2008-01-16
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
Question by:dbkn
    LVL 26

    Expert Comment

    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 ..

    LVL 6

    Expert Comment

    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", "'beige';'hand'");
                            e.Item.Attributes.Add("onmouseout", "'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

    LVL 6

    Expert Comment

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

     please change this line  to

      e.Item.Attributes.Add("onclick", jScript)

    Author Comment

    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?
    LVL 6

    Accepted Solution

    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", "'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.

    LVL 26

    Expert Comment

    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 ..


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Suggested Solutions

    ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
    Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now