Visibility of selectedindex of a datagriditem

R

Richard Loupatty

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
 
M

Mike Moore [MSFT]

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_SelectedIndexChanged", 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.


--------------------
 
R

Richard Loupatty

Mike,

This indeed did the trick. Thank You

Richard

"Mike Moore [MSFT]" said:
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_SelectedIndexChanged", 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" <[email protected]>
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: <[email protected]>
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: (e-mail address removed)
Path:
cpmsftngxa07.phx.gbl!cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!t-online.de!news-lei1.dfn.de!news-fra1.dfn.de!news2.telebyte.nl!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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top