Mkar
Mkar

Reputation: 21

ASP.NET GridView focus selected row

I am fairly new to ASP.NET. I have a GridView control which has many rows. Based on selection of each row I need to enable/disable few list and text controls on the collapsible panel in a ASCX.

The issue I am facing is whenever I select any row the GridView sets the focus on the first row all the time due to postback.

How do I set the focus on the selected row?

Can I use GetPostBackClientHyperlink in the RowDataBound somehow to register a client-side script?

Reply with some code is much appreciated.

Upvotes: 2

Views: 10679

Answers (2)

eDriven_Levar
eDriven_Levar

Reputation: 396

You can also use jQuery. I added a <div> with an ID that is only shown when a row is using the edit template. $('#hiddenDIV').focus();

Upvotes: 0

mayor
mayor

Reputation: 641

Add a handler to the SelectedIndexChanged event of your GridView and insert the following code into this handler:

GridView1.SelectedRow.Focus(); // where GridView1 is the name of your GridView

Upvotes: 2

Related Questions