Showing posts with label GridView. Show all posts
Showing posts with label GridView. Show all posts

Sunday, 27 September 2009

Simple tips: Set Focus to TextBox in GridView (edit mode)


If you use TemplateField like


            
                
             
            
                
             
        


 You could do it in RowEditing, for example:

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
            //Normal turning to edit
            GridView1.EditIndex = e.NewEditIndex; 
            BindGrid();

            //Set the focus to control on the edited row
            GridView1.Rows[e.NewEditIndex].FindControl("txtEdit").Focus();
        }

I'm binding the grid manually, therefore there is setting the index and calling databinding functions. However, with BoundField (I have CommandField as left most column) it could be something like:

GridView1.Rows[e.NewEditIndex].Cells[1].Controls[0].Focus();

where Cells[index] is the one you should be modifying based on which column it is in question (still doing in RowEditing)
In case you use data-source controls, it might be feasible to do it in RowDataBound:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowState == DataControlRowState.Edit)
            {
                //Set the focus to control on the edited row
                e.Row.Cells[1].Controls[0].Focus(); 
                //Or to a specific control in TemplateField
               // e.Row.FindControl("txtEdit").Focus(); 
            }
        } 

Tuesday, 10 February 2009

Blog all about Dotnet Technologies...............





Most Useful JavaScript Functions :





 a superb blog............................ 

SmartNavigation Vs MaintainScrollPositionOnPostback in ASP.net 2.0

MaintainScrollPositionOnPostback in ASP.net 2.0

Every one of us know very well about the feature of "SmartNavigation", BUT In Visual studio version 2.0 and above "SmartNavigation" has become obsolete. Now What is the alternate for this, if you want to achieve same feature as "SmartNavigation" then use "MaintainScrollPositionOnPostback".

How to use

Just set Page.MaintainScrollPositionOnPostback = true in page load event and java script will be inserted into your rendered page that maintains the scroll position in the browser window for all post back.
Believe me it's really a good feature in ASP.net 2.0, it would reduce lots of coding effort to maintain scroll position in web page.

Another alternate to maintain page scroll position

This way is same what we do for HTML documents. The following lines you can write into the server side or client side. Below example to write in server side

StringBuilder maintainScrollPosition = new StringBuilder();

maintainScrollPosition.Append("");

Page.ClientScript.RegisterStartupScript(this.GetType(), "Contents", maintainScrollPosition.ToString());

Here entity[0] has a value where you want to set scroll position, in other word it's a flag.You can assume entity[0] is heading in your aspx page and after postback you want scroll position be on this heading.