C implements the method of adding double click events to DataGrid cell rows

  • 2021-07-10 20:36:07
  • OfStack

This article illustrates how the C # implementation adds a double-click event to an DataGrid cell line. Share it for your reference. The details are as follows:

What I need to do now is to display the corresponding selected data information when I click a row of DataGrid, and pop up the Delete dialog box when I double-click the same row. What should I do? Since the click problem is so simple that it will not be elaborated, let me talk about how the double-click event is realized.

The ItemDataBound event of DataGrid is used here. We can add the following code to the required program to realize the double-click function.


private void DataGrid1_ItemDataBound(
 object sender, 
 System.Web.UI.WebControls.DataGridItemEventArgs e
) 
{ 
 if ((e.Item.ItemType == ListItemType.Item) || 
  (e.Item.ItemType == ListItemType.AlternatingItem) || 
  (e.Item.ItemType == ListItemType.SelectedItem) ) 
 { 
  e.Item.Attributes.Add ("ondblclick", 
   "javascript:return confirm(' Determine deletion " + e.Item.Cells[1].Text + "?');"); 
 } 
}

I hope this article is helpful to everyone's C # programming.


Related articles: