views:

222

answers:

1

I'm using gridview with templates to show and edit some information from a sql database.

When I edit and change the data in that row and then click enter it automatically presses the highest on page button which uses submit to server set to true which means it'll try to delete instead of update.

I've have tried setting a panel round the gridview and setting the panel's default button to the "updatebutton" but it won't allow that because it can't 'see' the buttons.

+2  A: 

You need to precess KeyDown or KeyPress event of the grid, and check if pressed key if Keys.Enter :

public partial class Form1 : Form
{
 public Form1()
 {
  InitializeComponent();
 }

 private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
 {
  if (e.KeyCode == Keys.Enter)
  {
   button1_Click(this, EventArgs.Empty);
  }
 }

 private void button1_Click(object sender, EventArgs e)
 {
  // Your logic here
 }
}
Veton