I am developing a small documents library app for my company using ASP.net with a SQL Server Express (R2 2008) back end. On my form I have a data bound Data List that displays each record in the Master library . There is an Edit button on the Item template and Cancel and Save buttons on the edit item template. If the user clicks the edit button on 20 (of > 200) the EditCommand fires fine but the list returns to the first record and they have to scroll down to find it again. In the Edit Command event I set the DataList EditItemIndex property to the index of the DataListItem that was clicked, then rebind the data to the control, like this:
Protected Sub MyDataList_EditCommand(source As Object, e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles MyDataList.EditCommand
Dim queryString As String = "SELECT TOP 100 PERCENT (Fields) FROM (MyTable)"
MyDataList.EditItemIndex = e.Item.ItemIndex
MyDataList.DataSource = GetData(queryString)
(GetData is what sets the data source of the Data list control and this works fine in all instances)
This happens with Cancel and Save also, it returns to the first record in the list. I want to stay on the current record and not have to scroll down to find it again.
What I am doing wrong? Thanks.