I have a gridview on my webpage nested in a div. The gridview has a template field containing a LinkButton. On click of LinkButton, RowCommand gets fired and some code is executed and there is a postback. I want the focus on same row in which LinkButton was clicked so that user can readily have a view of changes made by RowCommand.
To achieve this, I have used the following code on top line of aspx page:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" MaintainScrollPositionOnPostback="true" %>
In the RowCommand, I have used the following code:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
int row = int.Parse(e.CommandArgument.ToString());
GridView1.SelectedIndex = row;
GridView1.SelectedRow.Focus();
}
It works fine.
The problem comes when I try to fix the height of the div in which gridview is nested and set overflow-y to auto. The gridview lines scroll in this area, select command also works but it fails to focus on the selected row.
Kindly help me with code for focusing on the selected row when div height is fixed and gridview scrolls.
I am using ASP.NET C# with sql server
Thanks for your help.