setting visible row of datagrid.

WellsCarrie

Well-known member
Joined
Jul 12, 2005
Messages
95
Location
Arkansas
Programming Experience
5-10
*answered* setting visible row of datagrid.

John is a saivor! See his answer below.


Ok just point me to the thread if this has been answered before. I couldn't find one.

I have a web page with 3 panels. One with filtering items (ddls, radio buttons, Calendars, ect.) The second one holds the master Order List datagrid. The third the Order completion event child datagrid.

The reason I use a panel is that when I had the Master Order List Paging the users complained that they didn't want to have to page through several(sometimes 50 to 100) pages to get to the order that they wanted to see events for. So I took paging off and gave them a 1/2 screen scrollable panel it allows about 30 rows (the same as the paging) to be seen at once. They love it, except, that when they click on the "Get Events" link the Master Order List datagrid rolls back to the top once the Event child datagrid has refreashed.

So Anybody out there have a way to make the selected Index row of a datagrid the one visible in the panel?

Thanks!
 
Last edited:
You probably have to use some Javascript to make the panel scroll to the same position. How did you make the ASP.Net 1.1 Panel scrollable?
 
style="overflow:auto"

I added a style tag as below


VB.NET:
<asp:Panel id="pnlOrders" style="OVERFLOW: auto" runat="server" Width="100%" BorderWidth="1" Height="240" BorderStyle="solid" BorderColor="#eeeeee"></asp:Panel>


Then anything you put inside the panel that takes up too much room will produce a scroll bar.

Any idea on what the javascript would look like?
 
Yes, I just wanted to make sure this was a standard Panel (=Div tag).
Here's the code, I used a Script tag in Head section with two Javascript functions:
HTML:
<script type="text/javascript">
function savescroll() {
var ps = document.getElementById("Panel1").scrollTop;
document.getElementById("Hidden1").value = ps;
}
function getscroll() {
var ps = document.getElementById("Hidden1").value;
document.getElementById("Panel1").scrollTop = ps;
}
</script>
Put onload event handler for Body tag to restore scroll position. Added a hidden input field and set it to runat=server used to store the scroll position value.
HTML:
<body onload="getscroll();">
<form id="form1" runat="server">
<div>
<input id="Hidden1" type="hidden" runat="server" />
<asp:Panel id="Panel1" runat="server" Height="114px" Width="330px" style="overflow:auto ">
</asp:Panel>
<asp:Button ID="Button1" runat="server" Text="postback" /></div>
</form>
</body>
Then set the onscroll event handler for the Panel1 div tag in page load:
VB.NET:
[SIZE=2][COLOR=#0000ff]Protected [/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] Page_Load([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Object[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) _
[/SIZE][SIZE=2][COLOR=#0000ff]Handles [/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].Load
[/SIZE][SIZE=2]  Panel1.Attributes.Add([/SIZE][SIZE=2][COLOR=#800000]"onscroll"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#800000]"savescroll();"[/COLOR][/SIZE][SIZE=2])
[/SIZE][SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE]
(I used a DataGrid dynamically added to Panel by code for testing, this code is not displayed here.)
 
Back
Top