Deep Copy ASP.NET GridView

I am creating a custom control for a group of peers and I am running into a road block. The goal of management is to provide an easy way to implement grids with nesting, sorting, etc.

To create nesting, I have a child GridView that serves as a plan for the rest of the children. I allow the developer to customize it the way they want, and then the user control makes several identical copies.

My problem is that I cannot completely copy child gratings. MemberWiseClone () does not work, and the GridView is not serializable.

My current solution is to manually copy the list of fields that, as I know, we will need (ID, CssClass, etc.), but which are clearly inadequate and do not even touch EventHandlers.

Is there a good way to deep copy a GridView - or - provide the functionality I described using another method?

+3
source share
4 answers

Do not forget that we are in an object-oriented language. I think you need to make your control by inheriting from BoundField and GridView objects. You can override the GridView CreateColumns function to use your new BoundField object instead of the default value.

Here's how I created a multi-column TreeView from a GridView, see here .

BoundFiled , , New, InitializeDataCell, OnDataBindField, ExtractValuesFromCell . , :

 Protected Overrides Sub InitializeDataCell(ByVal cell As
 System.Web.UI.WebControls.DataControlFieldCell, 
 ByVal rowState As System.Web.UI.WebControls.DataControlRowState)
    ... ect...
                AddHandler cell.DataBinding, AddressOf OnDataBindField

            End Sub

GridView , , , . OnInit, InitializeRow, PerformDataBinding, OnPreRender, OnSorting, UpdateRow, InitializeDataCell .. , .

, . GridView .

alt text

0

viewstate controlstate? ​​ viewstate. viewstate, gridview, , . IStateFormatter

. , , .

0

, , GridView html , html RenderControl.

:

http://forums.asp.net/p/1016960/1368933.aspx

System.IO.StringWriter stringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWriter = new System.Web.UI.HtmlTextWriter(stringWriter);
gridView.RenderControl(htmlWriter);
string s = stringWriter.ToString();

EventHandler.

0
    Protected Sub GridView1_Init(sender As Object, e As System.EventArgs) Handles GridView1.Init
    Dim ThisGridView As GridView = sender
    ThisGridView.ApplyStyle(MasterGridView.ControlStyle)
End Sub
0

Source: https://habr.com/ru/post/1725099/


All Articles