Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 16th, 2003, 10:43 AM
Authorized User
 
Join Date: Jun 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default DataList always goes to the top

Hi

Has anyone got a solution to this?

When using a DataList which used the Edit and Update buttons, the control always goes to the top of all the items and the user has to scroll down to where the edit template is already open.

Is there any way to stop this so that when the user hits edit then the selected record stays in the field of view so that scrolling is not necessary


TIA


Grahame

Best wishes,
Grahame

Grahame Hambleton
Webmaster / Developer
Saïd Business School
University of Oxford
Saïd Business School
Park End Street
Oxford OX1 1HP
Tel: +44 (0) 1865 288863
Fax: +44 (0) 1865 288805
email: [email protected]
http://www.sbs.ox.ac.uk
__________________
Best wishes,
Grahame

Grahame Hambleton
Webmaster / Developer
Saïd Business School
University of Oxford
Saïd Business School
Park End Street
Oxford OX1 1HP
Tel: +44 (0) 1865 288863
Fax: +44 (0) 1865 288805
email: [email protected]
http://www.sbs.ox.ac.uk
 
Old December 16th, 2003, 03:00 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hello,

You could store the selected index value and set it manually in your code when you edit or update. That's one possibility. Also, are you talking a windows project or a web project?

Brian
 
Old December 17th, 2003, 04:48 AM
Authorized User
 
Join Date: Jun 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

HI Brian,

I am using a web form. I have the index and the edit template is showing on the screen but because the DataList is showing perhaps 90 people then the user has to use the scroll bar in order to come to the point where the edit template is showing. The thing is working fine and it's only an issue when many records are returned.

reg'ds


Grahame

Best wishes,
Grahame

Grahame Hambleton
Webmaster / Developer
Saïd Business School
University of Oxford
Saïd Business School
Park End Street
Oxford OX1 1HP
Tel: +44 (0) 1865 288863
Fax: +44 (0) 1865 288805
email: [email protected]
http://www.sbs.ox.ac.uk
 
Old December 18th, 2003, 05:58 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hmm, that's a good question; I'm not really familiar with the data list control, is there an scroll() method or scrolling event that allows you to specify an X/Y coordinate or something like that (maybe prerender event)? Otherwise, maybe you could create your own data list control by inheriting it...

I'm surprised that you would have to go to the top of the list. Do you have any code in an event that does redirecting in the data list, whether it is related to this functionality or not?
 
Old December 18th, 2003, 06:30 PM
Authorized User
 
Join Date: Nov 2003
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to KABay
Default

I too am not very familiar with the DataList control. I had a similar sort of problem when I was using a DataGrid control. When I selected a specific row of the grid (which was a summary view of up to 100 data records) I wanted to display detail information for that record and hide the grid. When the user was done viewing/editing the detail data I had to redraw the grid with the updated data. But when I did that the focus was always back on the first row of the grid.

To solve my problem I added a template column to my grid (as the first column) and put a 'literal' control in it as my "anchor". Then I programatically set the value of each instance of the anchor after having loaded the grid. When the user selects a row to view detail information for I save the 'key' to the row in a ViewState variable and when I come back I retrieve it using some client-side java code.

The (sorry it's VB and no pun intended) basic code is as follows:

Code:
    Private Sub FillGrid(ByVal currentSqlCommand As SqlClient.SqlCommand)
        Dim dr As SqlClient.SqlDataReader
        Dim item As System.Object

        sqlDBCn.Open()
        dr = currentSqlCommand.ExecuteReader()
        If dr.HasRows Then
            dgrdItems.DataSource = dr
            dgrdItems.DataBind()
        End If

        dgrdItems.SelectedIndex = -1
        dr.Close()
        sqlCnDB.Close()

        ...

        ' Set up the Anchor control with the row location so we are ready to
        ' return from Details view to whatever row was selected in Summary view
        For Each item In dgrdItems.Items
            item.FindControl("ctlAnchor").Text = "<a name=""" & item.ItemIndex.ToString & """>"
        Next

    End Sub

    Private Sub dgrdItems_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dgrdItems.SelectedIndexChanged

        With sender.Items(dgrdItems.SelectedIndex)
            ...
            ' Save the row location we selected so we can return to it
            ViewState("GridBookmark") = .ItemIndex - 3)
        End With
    End Sub

    Private Sub cmdReturnToSummaryView_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdReturnToSummaryView.Click

        ... 
        ' Redraw the grid with the changes and any others that other users may
        ' have made while we were working on this record.

        FillGrid(sqlCmdPrev)
        SetGridBookmark()
    End Sub

    Private Sub SetGridBookmark()

        Dim jScript As New System.Text.StringBuilder

        jScript.Append("<script language=""JavaScript"">")
        jScript.Append("location.href=""#")
        jScript.Append(ViewState("GridBookmark").ToString)
        jScript.Append(""";")
        jScript.Append("</script>")

        Me.RegisterClientScriptBlock("Bookmark", jScript.ToString())
    End Sub





Similar Threads
Thread Thread Starter Forum Replies Last Post
Datalist inside datalist amit.jagtap ASP.NET 2.0 Professional 1 September 4th, 2007 05:03 AM
SELECT TOP n rgerald SQL Server 2000 3 May 12th, 2006 04:03 PM
SELECT TOP n NOT SELECTING TOP n! ibi SQL Language 8 March 30th, 2005 08:08 PM
SELECT TOP FROM HAVING khatfield29 SQL Language 1 August 23rd, 2004 02:41 PM
TOP N Analysis rj SQL Server 2000 1 July 13th, 2003 10:21 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.