473,396 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Visibility of selectedindex of a datagriditem

I put a datagrid in a panel with an overflow set on auto.
I want to show just 5 items in the grid.

My question is how to make sure that the selecteditem is always visible in
the grid. Because now i have this situation that after each selection (I use
the itemcommand) the grid starts from the top.
when i (for example) set selectedindex = 8, the selection is made, but not
visible to me. I have to scroll down first.
tia

Richard Loupatty
Nov 18 '05 #1
2 1744
Hi Richard,

I think this will do what you want.

**** Panel and grid
<asp:Panel id="Panel1" runat="server" Height="100px" style="OVERFLOW: auto">
<asp:DataGrid id="DataGrid1" runat="server">
<Columns>
<asp:ButtonColumn Text="Select"
CommandName="Select"></asp:ButtonColumn>
</Columns>
</asp:DataGrid>
</asp:Panel>

**** Code
Private Sub DataGrid1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles DataGrid1.SelectedIndexChanged

Dim s As String = "<script language='javascript'>
document.all('DataGrid1_tr_" & DataGrid1.SelectedIndex &
"').scrollIntoView(); </script>"

RegisterStartupScript("DataGrid1_SelectedIndexChan ged", s)
End Sub
Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemDataBound

Dim tr As DataGridItem
tr = e.Item
tr.Attributes.Add("id", "DataGrid1_tr_" & e.Item.ItemIndex)
End Sub
Does this answer your question?

Thank you, Mike
Microsoft, ASP.NET Support Professional

Microsoft highly recommends to all of our customers that they visit the
http://www.microsoft.com/protect site and perform the three straightforward
steps listed to improve your computer’s security.

This posting is provided "AS IS", with no warranties, and confers no rights.
--------------------
From: "Richard Loupatty" <r.********@miodevelopment.nl>
Newsgroups: microsoft.public.dotnet.framework.aspnet
Subject: Visibility of selectedindex of a datagriditem
Date: Mon, 12 Jan 2004 11:30:56 +0100
Organization: MIO Development bv
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.3790.0
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
Lines: 15
Message-ID: <40***********************@news.versatel.net>
NNTP-Posting-Date: 12 Jan 2004 10:31:01 GMT
NNTP-Posting-Host: unlabelled-95-38-59-62.versatel.net
X-Trace: 1073903461 news.versatel.net 37823 62.59.38.95:64443
X-Complaints-To: ab***@versatel.net
Path: cpmsftngxa07.phx.gbl!cpmsftngxa06.phx.gbl!TK2MSFTN GP08.phx.gbl!newsfeed00.su
l.t-online.de!t-online.de!news-lei1.dfn.de!news-fra1.dfn.de!news2.telebyte.n
l!news.cambrium.nl!news.cambrium.nl!news.cambrium. nl!news2.euro.net!beastial
ity.euro.net!postnews1.euro.net!news.versatel.net! not-for-mail Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.framework.aspnet:201370
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet

I put a datagrid in a panel with an overflow set on auto.
I want to show just 5 items in the grid.

My question is how to make sure that the selecteditem is always visible in
the grid. Because now i have this situation that after each selection (I use the itemcommand) the grid starts from the top.
when i (for example) set selectedindex = 8, the selection is made, but not
visible to me. I have to scroll down first.
tia

Richard Loupatty


Nov 18 '05 #2
Mike,

This indeed did the trick. Thank You

Richard

""Mike Moore [MSFT]"" <mi****@online.microsoft.com> wrote in message
news:77**************@cpmsftngxa07.phx.gbl...
Hi Richard,

I think this will do what you want.

**** Panel and grid
<asp:Panel id="Panel1" runat="server" Height="100px" style="OVERFLOW: auto"> <asp:DataGrid id="DataGrid1" runat="server">
<Columns>
<asp:ButtonColumn Text="Select"
CommandName="Select"></asp:ButtonColumn>
</Columns>
</asp:DataGrid>
</asp:Panel>

**** Code
Private Sub DataGrid1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles DataGrid1.SelectedIndexChanged

Dim s As String = "<script language='javascript'>
document.all('DataGrid1_tr_" & DataGrid1.SelectedIndex &
"').scrollIntoView(); </script>"

RegisterStartupScript("DataGrid1_SelectedIndexChan ged", s)
End Sub
Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemDataBound

Dim tr As DataGridItem
tr = e.Item
tr.Attributes.Add("id", "DataGrid1_tr_" & e.Item.ItemIndex)
End Sub
Does this answer your question?

Thank you, Mike
Microsoft, ASP.NET Support Professional

Microsoft highly recommends to all of our customers that they visit the
http://www.microsoft.com/protect site and perform the three straightforward steps listed to improve your computer's security.

This posting is provided "AS IS", with no warranties, and confers no rights.

--------------------
From: "Richard Loupatty" <r.********@miodevelopment.nl>
Newsgroups: microsoft.public.dotnet.framework.aspnet
Subject: Visibility of selectedindex of a datagriditem
Date: Mon, 12 Jan 2004 11:30:56 +0100
Organization: MIO Development bv
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.3790.0
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
Lines: 15
Message-ID: <40***********************@news.versatel.net>
NNTP-Posting-Date: 12 Jan 2004 10:31:01 GMT
NNTP-Posting-Host: unlabelled-95-38-59-62.versatel.net
X-Trace: 1073903461 news.versatel.net 37823 62.59.38.95:64443
X-Complaints-To: ab***@versatel.net
Path:

cpmsftngxa07.phx.gbl!cpmsftngxa06.phx.gbl!TK2MSFTN GP08.phx.gbl!newsfeed00.su l.t-online.de!t-online.de!news-lei1.dfn.de!news-fra1.dfn.de!news2.telebyte.n l!news.cambrium.nl!news.cambrium.nl!news.cambrium. nl!news2.euro.net!beastial ity.euro.net!postnews1.euro.net!news.versatel.net! not-for-mail
Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.framework.aspnet:201370 X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet

I put a datagrid in a panel with an overflow set on auto.
I want to show just 5 items in the grid.

My question is how to make sure that the selecteditem is always visible in the grid. Because now i have this situation that after each selection (I

use
the itemcommand) the grid starts from the top.
when i (for example) set selectedindex = 8, the selection is made, but not visible to me. I have to scroll down first.
tia

Richard Loupatty

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jukka K. Korpela | last post by:
I have noticed that the meaning of visibility: collapse has been discussed on different forums, but with no consensus on what it really means. Besides, implementations differ. The specification...
12
by: lawrence | last post by:
The following function correctly makes everything invisible but then fails to turn the one chosen DIV back to visible. I imagine I'm getting the syntax of the variable wrong? I've tried this with...
4
by: lawrence | last post by:
Can anyone tell me why this code works in Netscape 7.1 but not in IE??? <SCRIPT type='text/javascript'> function makeVisible(nameOfDiv) {...
8
by: TTroy | last post by:
I have a few questions about "scope" and "visibility," which seem like two different things. To me "visibility" of the name of a function or object is the actual code that can use it in an...
0
by: Spitz | last post by:
I keep getting the exception An unhandled exception of type 'System.NullReferenceException' occurred in system.windows.forms.dll (Additional information: Object reference not set to an instance of an...
0
by: Paul Perot | last post by:
Hi All: I am populating a Data Table with File/Folder information from my drive... I am then binding this data table to a DataGrid. Due to the size of the DataGrid data, I use the built in...
5
by: Lie | last post by:
Hi all, I have problem in getting selectedindex of multiple listbox selection in a datagrid. I have a listbox with multiple selection mode inside datagrid. In Edit mode, I need to get back all...
2
by: Mike Gaab | last post by:
VS 2005 What is the difference between the DataGridItem's ItemIndex and DataSetIndex? Aren't they the same thing? Here is what I found on msdn. ItemIndex Gets the index of the DataGridItem...
3
by: Steve Hershoff | last post by:
Hi everyone, I'm wondering if anyone has a suggestion on how to do this, or if it's even possible. In my datagrid's OnItemDataBound function I'd like to somehow "add" a child row beneath one...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.