Different111222
Different111222

Reputation: 1535

How do I clear selection of a gridview row?

I'm using C# ASP.NET VS2010.

I have a GridView including a select command button.

This select button points to an action in the code behind C# page activated upon selection.

After performing all required action I would like to clear the selection.

For example: in case the ID="gvInfo" I would like to use something like gvInfo.Deselect();

How do I do that?

Upvotes: 21

Views: 38028

Answers (5)

Behnam-s
Behnam-s

Reputation: 131

You can use the following method:

GridView1.SelectRow(-1);

Upvotes: 0

anon
anon

Reputation:

As explained in https://social.msdn.microsoft.com/Forums/en-US/8a4937d1-531a-49d7-9392-bb76cb9bfcb7/how-to-clear-selectedrow-in-a-gridview?forum=aspwebformsdata

Gridview has a property called SelectedIndex. If you want to unselect any rows then set this property to -1.

Upvotes: 41

Catto
Catto

Reputation: 6409

Try this:

gvInfo.SelectedIndex = -1;

Upvotes: 12

Bitterblue
Bitterblue

Reputation: 14075

In desktop apps with DataGridView there is no SelectedIndex:

gridView1.ClearSelection();

Upvotes: 6

I did it this way and it works perfectly.

gridViewName.GetSelectionModel().ClearSelection();

I hope it can work for someone.

Upvotes: 0

Related Questions