Click here to Skip to main content
15,880,543 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:
C#
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" MaintainScrollPositionOnPostback="true"  %>

In the RowCommand, I have used the following code:
C#
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
            // code to be executed
           int row = int.Parse(e.CommandArgument.ToString()); // commandargument is same as row index
            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.
Posted
Updated 6-Jun-16 0:33am

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900