将gridview放在更新面板上

时间:2014-06-06 09:12:16

标签: asp.net gridview updatepanel

首先,我是ASP.NET的初学者。我知道很多经典的ASP。

我正在开发应用程序/框架oracle实用程序。在过去,我创造了剪辑'在经典ASP中,这是gridviews。网页上有几个剪辑。所有这些网格视图都有页面索引。此时每个网格显示5条记录。因此,如果有18条记录,则有4页。

分页,数据绑定等工作正常。

但是我已经说过,页面上有几个剪辑。例如,用户想要查看页面中间的剪辑。当他点击该剪辑的下一页时,将执行提交并提交整个页面并将其定位在页面顶部。这不是用户友好的,因为用户必须搜索/向下滚动到他正在查看的剪辑。

我正在寻找,我不知道我是否正确说出,将剪辑的每个网格视图绑定到他自己的更新面板,这样如果用户点击下一页的某个gridview,只刷新gridview而不是完整的页面(AJAX?)。

以下是代码:

namespace Lodestar.Web.WebParts {
    public class CustomerCustomWebpartGasGVExSub : WebPart {
        //define variables

        private GridView CustConGrid;
        //I have defined this by myself
        private UpdatePanel UpdatePanel1;

        private LiteralControl LinkBox;

        public override string Title {
            get {
                return _title;
            }
            set {
                _title = value;
            }
        }

        //construtor
        public CustomerCustomWebpartGasGVExSub() {}

        protected override void CreateChildControls() {
            Controls.Clear();

            //Create the contract view.
            CustConGrid = new GridView();
            CustConGrid.EnableTheming = true;
        CustConGrid.SkinID = "CompacGrid";
        CustConGrid.PageSize = 5;
        CustConGrid.AllowPaging = true;
        CustConGrid.AutoGenerateColumns = false;
        CustConGrid.EmptyDataText = I18n.FM("GVClip_NoContracts");

        //I have defined this by myself    
        UpdatePanel1 = new UpdatePanel(); 

        //Create the db instance and retrieve the Customer UID and ID from the session page.
        ....
        using (DataTable dt = db.GetEntity("CUSTOMER", filter)) {
            //Retrieve the Customer information from the database.
            ....                
            //Render the contract table panel.

            using (DataTable cdt = TableFromReader(cdb.GetDataReader(xslFileGasGV, "StoredProcedure", lsdbparams, 9999, 1))) {

            }

            //Contract ID
            HyperLinkField ContractIdFld = new HyperLinkField();
            ContractIdFld.HeaderText = I18n.FM("ContractID");
            ContractIdFld.DataTextField = "CONTRACTID";
            ContractIdFld.DataNavigateUrlFields = new string[] {"UIDC"};
            string url = string.Format("~/..../..../......asp?SessionId={0}", HttpContext.Current.Server.UrlEncode(SessionContext.Id));
            ContractIdFld.DataNavigateUrlFormatString = url + "&UIDC={0}";
            CustConGrid.Columns.Add(ContractIdFld);

            //Revision
            BoundField RevisionFld = new BoundField();
            RevisionFld.HeaderText = I18n.FM("GRevision");
            RevisionFld.DataField = "REVISION";
            CustConGrid.Columns.Add(RevisionFld);

            //Contract Type Code

            //Category

            //Status

            //Bind and add row
            CustConGrid.PageIndexChanging += new GridViewPageEventHandler(CustConGrid_PageIndexChanging);
            Controls.Add(CustConGrid);
            CustConGrid.DataBind();
        //UpdatePanel1.PageIndexChanging += new    GridViewPageEventHandler(CustConGrid_PageIndexChanging);
//Tried something by myself, but is not working
UpdatePanel1.ContentTemplateContainer.Controls.Add(CustConGrid);
            }
        }

        protected override void RenderContents(HtmlTextWriter writer) {}

        public DataTable TableFromReader(IDataReader dr) {}

        void CustConGrid_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            CustConGrid.PageIndex = e.NewPageIndex;
            CustConGrid.DataBind();
        }

        private void GetSessionInfo() {}
    }
}

2 个答案:

答案 0 :(得分:0)

通过在页面标记中添加此MaintainScrollPositionOnPostback,您可以解决在回发后保持滚动位置的问题。

<%@ Page Title="" MaintainScrollPositionOnPostback="true"  Language="C#" 

答案 1 :(得分:0)

好的,我刚试过它,它对我们有用。我已经添加了:     MaintainScrollPositionOnPostback = “真”

到web.config中的页面标记。

但要学习更多的ASP.NET是否也可以在代码中使用更新面板? (例如在方法page_onload {}中)