Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have a grid with hundred rows (no check boxes in gridview), i am searching for the records in the grid through
a search button, search button is located out side the grid. if record is found, then the row will be highlighted.

My problem is i want to scroll down the page to the row highlighted.

how can i do that??

Thanks in advance.
Posted

GridViewRow row = grVw.SelectedRow;
row.Cells[0].Focus();

By adding these two lines we can scroll the grid.But Focus will work only for editable controls. example like checkbox,hyperlinkfield,linkbutton etc.
 
Share this answer
 
v2
There are a few ways to scroll the DataGridView - First setting the CurrentCell property automatically scrolls the cell into view. You can also set the FirstDisplayScrollingRowIndex to scroll the grid manually.
 
Share this answer
 
Comments
swathi6589 7-Dec-11 7:18am    
I am using gridview not datagridview,can you please help me for that.
try this..

declare these two variables globally..

C#
int pageindex = -1;
int rowindex = -1;


do your search..

C#
for (int i = 0; i < grid_view.PageCount; i++)
       {
           grid_view.PageIndex = i;
           grid_view.DataSource = ds;
           grid_view.DataBind();
           foreach (GridViewRow row in grid_view.Rows)
           {
               //your search match condition
               // if match
               pageindex = i;
               rowindex = row.RowIndex;
               break;
           }
           if (pageindex > 0)
           {
               break;
           }
       }

       grid_view.PageIndex = pageindex;
       grid_view.DataSource = ds;
       grid_view.DataBind();


later on databound event..

C#
if(grid_view.PageIndex == pageindex)
 {
      if(e.Row.RowIndex == rowindex)
      {
          e.Row.BackColor = System.Drawing.Color.Red;
      }
 }


hope it works..
 
Share this answer
 
Comments
swathi6589 7-Dec-11 7:21am    
Thank you Karthik

This is used for highlighting the row where as I want to scroll window to highlighted row.
Dear Swathi

u have add the following code in source part in between gridview


 
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