• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 587
  • 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:

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

 <asp:DataGrid id="MyDataGrid" runat="server"
         BorderColor="black" GridLines="Vertical"
         cellpadding="4" cellspacing="0"
         AutogenerateColumns = "True"
         AllowSorting="True"
         cssClass="DataGrid"
         AllowPaging="True"
         HeaderStyle-BackColor="Black"
         HeaderStyle-ForeColor="White"
         HeaderStyle-Font-Bold="True"
         OnSortCommand="SortCommand_OnClick"
         OnPageIndexChanged="PageIndexChanged_OnClick"
         PageSize="20"
         PagerStyle-Mode="NumericPages"
         OnItemDataBound="MyDataGrid_ItemDataBound"
         ItemStyle-BackColor="#ffffff"
         AlternatingItemStyle-Backcolor="#cccccc"
         PagerStyle-HorizontalAlign="Right"/>

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
0
dbkn
Asked:
dbkn
  • 3
  • 2
1 Solution
 
RejojohnyCommented:
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 ..

Rejo
0
 
SandeepRRCommented:
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

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

 please change this line  to

  e.Item.Attributes.Add("onclick", jScript)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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?
0
 
SandeepRRCommented:
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.

Regards
SandeepRR
0
 
RejojohnyCommented:
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 ..

rejo
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

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