Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Open scrolling gridview with record closest to system date using FirstDisplayedScrollingRowIndex

Posted on 2009-04-14
9
Medium Priority
?
666 Views
Last Modified: 2013-11-26
I have a simple gridview with select records which include a date field.  The records include dates both before and after the system date, which are actually dated items entered for an entire year at a time.  I would like my scrolling gridview to open with the top record being the closest match to the current system date, even though there may not be an exact match (no record date matching system date).  But when the user opens the gridview, they will be at the top of the records whose date matches the current system date.  I am not an experienced programmer and have done most of the asp.net web site with Visual Studio 2008 and SQL Server.  I can code a bit but would need some help.  I am pretty sure what I want to do is with FirstDisplayedScrollingRowIndex, but I am not sure how.

Thanks for any help.
0
Comment
Question by:hconant
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 24148230
You have a confusing array of clues:

1) WinForms grid = DataGridView (not GridView)

2) You added this to ASP.NET (which would indicate GridView)

3) You mentioned FirstDisplayedScrollingRowIndex, which applies to DataGridView.

4) You mentioned "ASP.NET web site".

Question clarity, and usable clues make it easier for experts to help get a question answered.

0
 

Author Comment

by:hconant
ID: 24149077
I also said, "I am not an experienced programmer," which is obvious.  Just the same, you have actually shed some light on this and I will try to clarrify the confusion I created.
This is a simple web site I created using Visual Studio 2008.  I am utilizing asp.net controls and the pages are *.aspx.  The view, form, or whatever is a gridview, not a datagridview.  I didn't even know the difference.  I take it from your comment that the FirstDisplayedScrollingRowIndex will not work with what I currently have?  As far as your #4, I am not sure what I should clarrify about that.  The site address is http://blockislandschool.net.  The page i am working on is the Calendar Monthly.  There are only a couple of records at this time since we are just developing this.  But when the DB gets larger, the datagrid will be a hassle because someone just wanting current events would have to scrool through the entire years events.  We choose t his format because it is easy for authorized users to edit and insert.  That is what the "edit" link does.  If there is an easier way that would be fine.  This is just a student project for our small school.
Thanks for your help
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 24149513
Just confirming that we are talking about a GridView and ASP.NET is enough clarification for now.

Are you talking about a GridView in a scrolling <div> element?  If you want to select a row, then you would need to set SelectedIndex to the row index.
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

Author Comment

by:hconant
ID: 24149713
Yes, it is a GridView in a scrolling div element.  I will read up a bit to learn about the SelectedIndex and row index.  Currently I just use the SELECT statement in SQL query for the records I want, and set the sort order the same way, so in this case it sorts by date which is one of the fields. I am not familiar with the entire indexing situation so I guess I need to read up on that.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 24151316
Are you using any paging, because I believe that will be confused with the SelectedIndex?
0
 

Author Comment

by:hconant
ID: 24152610
No paging.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 24153509
I believe that setting GridView.SelectedIndex should be what you are after.
0
 

Author Comment

by:hconant
ID: 24157730
Can you expand upon that a bit?  I do not see how to utilize that in my situation, understanding that I have very little experience in programming.
Thanks
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 total points
ID: 24164215
Actually, you will need more than just code-behind.  You are going to need to use a little JavaScript to scroll:

http://forums.asp.net/p/1383518/2934022.aspx

<div runat="Server" id="divIncidentList" style="width:225px; height:400px; overflow:scroll;">
<asp:GridView ID="gvIncidentList" ...

   I then register a StartUp Script Block when the page loads. This JavaScript makes the ScrollTop of the div equal to the offsetTop of the selected row.

If Me.gvIncidentList.SelectedIndex >= 0 Then
   Dim Script As New StringBuilder
   Script.Append("<script language=""javascript"" type=""text/javascript"">" & vbCrLf)
   Script.Append("var r = document.getElementById('" & Me.gvIncidentList.SelectedRow.ClientID & "');" & vbCrLf)
   Script.Append("var d = document.getElementById('" & Me.divIncidentList.ClientID & "');" & vbCrLf)
   Script.Append("d.scrollTop = r.offsetTop;" & vbCrLf)
   Script.Append("</script>")
   Dim cs As ClientScriptManager = Page.ClientScript
   cs.RegisterStartupScript(Me.GetType, "IncidentListBoxLoadScript", Script.ToString)
End If

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question