c# - ASP.net gridview, autorefresh, txt as source and maintain scroll position -
c# - ASP.net gridview, autorefresh, txt as source and maintain scroll position -
i want gridview emulate console, text file have server console log.
i want to:
*refresh when file changes.(thus timer)
*scroll bar position maintained when updated, unless @ bottom.
*when scroll bar position @ bottom,stay @ bottom after databind update.
current problem: on timer, databind() moves scrollbar position top, , refresh can't scroll downwards @ all.
here current code. give thanks help!
asp.net
<%@ page language="c#" autoeventwireup="true" codebehind="test console.aspx.cs" inherits="webapplication1.test_console" %> <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> </head> <body> <form id="form1" runat="server"> <div> <asp:updatepanel id="updatepanel1" runat="server"> <contenttemplate> <asp:scriptmanager id="scriptmanager1" runat="server"> </asp:scriptmanager> <asp:timer id="timer1" runat="server" interval="30" ontick="timer1_tick"></asp:timer> <div style="width: 100%; height: 400px; overflow: scroll"> <asp:gridview id="gridview1" runat="server" maintainscrollpositiononpostback="true"> </asp:gridview> </div> </contenttemplate> </asp:updatepanel> </div> </form> </body> </html>
c#
using system; using system.collections.generic; using system.linq; using system.web; using system.web.ui; using system.web.ui.webcontrols; using system.io; namespace webapplication1 { public partial class test_console : system.web.ui.page { protected void page_load(object sender, eventargs e) { streamreader objstreamreader = new streamreader(server.mappath("textfile.txt")); var arrtext = new list<string>(); // ' loop through file , add together each line arraylist while( objstreamreader.peek() >= 0){ arrtext.add(objstreamreader.readline()); } //' close reader objstreamreader.close(); //' bind results gridview gridview1.datasource = arrtext; gridview1.databind(); } protected void timer1_tick(object sender, eventargs e) { gridview1.databind(); } } }
found of reply here http://forums.asp.net/t/1220070.aspx?how+to+maintain+scroll+position+in+gridview+or+datagrid+during+postback
using ajax , these 2 functions
function func() {//document.getelementbyid("hdnscrolltop").value document.getelementbyid("divscroll").scrolltop = document.getelementbyid("hdnscrolltop").value; } function func2() { var s = document.getelementbyid("divscroll").scrolltop; document.getelementbyid('hdnscrolltop').value = s;
c# asp.net gridview scrollbar refresh
Comments
Post a Comment