Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with gridview edit behavior

Status
Not open for further replies.

bookouri

IS-IT--Management
Feb 23, 2000
1,464
US
I have tried everything i can find online and can't fix this problem. When i click EDIT in my gridview and the row being edited is several pages down the screen, the page jumps back to the top and i have to scroll back down to the row that is now in edit mode.

Can anybody point me to anything that will fix this? I need the row being edited to keep focus so the user doesnt have to page up and down the screen to get to it.

thanks for any suggestions
 
You can use MaintainScrollPositionOnPostback="true" in your page directive in the HTML markup. However, it won't work in FireFox, it does work in IE and Chrome. If you search around, I believe the recommended way of doing it is with javascript. Google around or ask in the javascript forum here.
 

I think this will get you started. You can insert a startup script in the grid view RowCommand handler to scroll the selected (or updated) row. I use TemplateFields to specify my own LinkButton for each function, but it should work for the generated controls. Since the Edit control is replaced with Update and Cancel links on edit, you may have to insert a static (or hidden) control in each Template (item, edit) that will always be available in the respective state in order for the JavaScript function to find it when the page is rendered back on the client.


Code:
Private Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand

' Template contains a linkButton with id=lnkInfo
SelectedRowUpdateClientIdLink = GridView1.Rows(e.CommandArgument).FindControl("lnkInfo").ClientID
if SelectedRowUpdateClientIdLink isNot Nothing then
     ClientScript.RegisterStartupScript(Page.GetType, "ScrollClient", "showGridRow('" & SelectedRowUpdateClientIdLink & "');", True)
End if
.
.

Insert this into your aspx markup:

Code:
<script type="text/javascript" language="javascript">

function showGridRow(elID) {
    var el = document.getElementById(elID);
    if (el)
        el.scrollIntoView(true);
}

</script>


Mark

"You guys pair up in groups of three, then line up in a circle."
- Bill Peterson, a Florida State football coach
 
Thanks, I tried the MaintainScrollPositionOnPostback="true" but it didnt work for me. There were conflicting reports that it would/would not work for the gridview control. I tried it anyway and id didnt work for me using any of the examples i could find.

I tried a variation on the gridview rowcommand too but the above one looks more "complete" than the example I was working on.

I'm going to give it another try since these seem to be the most referenced methods.
 
I've tried variations on both the above suggestions and still have not managed to get anything to work.

I dont get any error messages or anything to point me to any problems, it just doesnt work for me...

any other suggestions would be appreciated

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top