How to generate scroll bars in DataGrid without scrolling the head

xiaoxiao2021-03-06  39

Author blog: http://blog.9cbs.net/cuike519/ We must encounter when we developed, when using DataGrid, because you don't want to page (there is not so much), it is displayed not in a page, at this time we hope A scroll bar appears in the DataGrid, you can scroll the data in the DataGrid without the up and down scroll, because the purpose of writing this article is to illustrate how to implement, the reader can think about the completion of the detailed problem (such as: page and must Rolling, etc.). In order to scroll to DataGrid, we need a Table scrolling JS script that allows the client (the JS code. I downloaded from the CodeProject), but I can't scroll the topic of Table (that is, the first line). We all know that DataGrid will generate a table after explaining the client, but this table is composed of , our script is required to use Table Thet and Tbody (in most customers This feature is used in the application, such as: the client's sort, and the column of torch, etc.), so our next task is how to add to our client's DataGrid. If you know about the user's custom control and the principles of the ASP.NET page, we know that the control is finally rendered (render) on the page, so we can override this method to complete the custom rendering of DataGrid. Listening to a little scary, how is the complex control? Don't worry, first we create a custom control as follows: public class powerDataGrid: system.Web.ui.WebControls.dataGrid This can be seen that our control is inherited in DataGrid, so our current control is not written In the case of a line of code, our control already has all the functions of DataGrid. Next, we have to build our JS code into our control, so that the page of the page will eventually have this JS code on the client to complete our scrolling tasks.

To do this we need to rewrite the method of pre-rendering: protected override void OnPreRender (System.EventArgs e) {base.OnPreRender (e); ResourceManager manager = new ResourceManager (this.GetType ()); ResourceSet resources = manager.GetResourceSet (System.Globalization.CultureInfo.CurrentCulture, true, true); if (Page.IsClientScriptBlockRegistered ( "SkySword.WebControl.PowerDataGrid Library")!) {String script = resources.GetString ( "ScrollTable"); this.Page.RegisterClientScriptBlock ( "SkySword.WebControl.PowerDataGrid Library", script); this.Page.RegisterStartupScript ( "SkySword.WebControls.PowerDataGrid Init", "