Full edit WebGrid control lrcgrid (6) - control presence
Create sub-control
Rewote the createChildControls () process, call the method of creating a child control Rebuild ()
Whenever the ASP.NET page framework needs to create a control tree, the CreateChildControls () method is called, and the method call is not limited to a specific phase of the life cycle of the control. For example, you can call CreateChildControls during the binding data during the loading page or during the rendering process.
Protected Override Void CreateChildControls ()
{
THIS.REBUILD ();
}
Rewriting the onprender (Eventargs E) process, registering the client script block, this script allows the user to enter the focus jump, and the part of the comment is the method of using the resource file.
Protected Override Void OnPrender (Eventargs E)
{
Base.onprender (e);
IF (this._istabchg)
{
IF (! page.isclientscriptblockregistered ("LRC_CHGTAB")))
{
String str_chgtab = @ "
IF (event.keycode == 13 && event.srcelement.Type! = 'button' && event.srcelement.type! = 'Submit' && event.srcelement.Type! = 'reset' && round.srcelement.type! = ' ')
Event.Keycode = 9;
->
script>
Page.RegisterClientScriptBlock ("LRC_CHGTAB", STR_CHGTAB);
}
}
/ * * ResourceManager manager = new ResourceManager (this.GetType ()); ResourceSet resources = manager.GetResourceSet (System.Globalization.CultureInfo.CurrentCulture, true, true);! If (Page.IsClientScriptBlockRegistered ( "LiuRuiCai.LrcGrid.Script" )) {string script = resources.GetString ( "ClientScript"); this.Page.RegisterClientScriptBlock ( "LiuRuiCai.LrcGrid.Script", script); string style = resources.GetString ( "ClientStyle"); this.Page.RegisterClientScriptBlock ( "Liuruicai.lrcgrid.style", style);} * /
}
Rebuild () method, when the control property is changed, this method can be called to restructive controls. It calls a series of internal processes: manages view status, empty control, reinitialize the data set, create title line, create data lines , Create operation line, etc.: ///
Public void rebuild ()
{
IF (this.currentpageIndex == -1)
THIS.CURRENTPAGEINDEX = 0;
THIS.CONTROLS.CLEAR ();
THIS.CLEARCHILDVIEWSTATE ();
THIS.ATRIBUTES.ADD ("Isdel", this._isdel.tostring ());
THIS.ATRIBUTES.ADD ("isadd", this._isadd.tostring ());
THIS.DBSET = NULL;
Base.createchildControls ();
// Create a header line
BuildTitle ();
INITDATASET ();
IF (this.dbset! = NULL)
{
IF (this.dbset.tables.count> 0)
{
IF (this.dbset.tables [0] .Rows.count> 0)
{
// Create a data line
Buildcol ();
}
}
}
// Create a operation line
Buildoper ();
}
Create a header row buildtitle () method, the title line, the header, according to the set title content property colsa, here I set up the header of each column to trigger server-side LinkButton, and edit in each The list of the list adds an HTMLANCHOR ▼, this HTMLANCHOR calls the client script chGedit () function, (Script Content, please refer to "Full Edit WebGrid Control LrcGrid (4) - Scripting Library and Style Table") Put a list in normal and Switch between edit mode, if the property settings allow deletion, add "All Remove" LinkButton in the title row
The head effect is as shown in the following figure:
Private void buildtitle ()
{
TableRow Tr = New TableRow ();
Tr.backcolor = _titcolor;
Tablecell tc = new TableCell ();
LinkButton LK = New LinkButton ();
HTMLANCHOR LKE = New htmlanchor ();
IF (colsa! = null)
{
For (int i = 0; i { Tc = new TableCell (); //tc.backcolor = _titcolor; // Sort IF (_issort) { // Full editing LK = new linkbutton (); LK.ID = "lrclk_" i; LK.Text = COLSA [I]; LK.Command = New CommandeventHandler (LK_COMMAND); LK.Commandargument = colsa [i]; Tc.Controls.Add (LK); } Else { Tc.Controls.Add (New LiteralControl (Colsa [i])); } IF (iSEDitcol (i)) { LKE = new htmlanchor (); lke.id = "lrclke_" i; Lke.innertext = "▼"; Lke.href = "JavaScript: chGEDIT (" i "," this.clientid ");"; Tc.Controls.Add (LKE); } Tr.cells.Add (TC); } IF (_ISDEL) { Tc = new TableCell (); LK = new linkbutton (); LK.ID = "lrcdelall"; LK.Text = "All Delete"; LK.Command = New CommandEventHandler (LKDEL_COMMAND); Tc.Controls.Add (LK); Tr.cells.Add (TC); } this.Rows.Add (TR); } } Create a data line buildcol () method, which traverses all items of the data set, display the records and fields in the data source as a row of forms and columns, add different controls to the table item according to the set properties, and Bind the value in the data source to these controls You can write data item values directly to Tablecell.Text Non-foreign Editor: Add a text box, and bind data items is the editorial column of the foreign key: Add a drop-down list, bind the drop-down list as a foreign key table And specify the selection item of the drop-down list according to the value of the data item. Add "Delete" in the last column to add "Delete" LinkButton as the picture shows: Private void buildcol () { For (Int i = this.rows.count; i> 1; I -) { This.Rows.Removeat (I-1); } TABLEROW TR; TableCell TC; TextBox TB; INT rownum = 0; Foreach (DataRow Dr in dbset.tables [0] .rows) { String forcolor; IF (this.backcolor.isknowncolor) FORCOLOR = this.backcolor.name; Else FORCOLOR = "#" this.backcolor.name; THIS.BACKCOLOR.B.TOSTRING (); Tr = new tablerow (); Tr.attributes.add ("onMouseover", "this.bgcolor = '# c1d2ee'"); Tr.attributes.add ("onMouseout", "this.bgcolor = '" forcolor "'"); Int rownumdata = rownum 1; Tr.attributes.add ("OnDBLClick", "ChGeditrow (" RowNumData.toString () "," this.clientID ");"); For (int i = 0; i { Tc = new TableCell (); if (iSEditcol (i)) { IF (isfkcol (i)) { IF (this.fklist (i, DR [i] .tostring ())! = null) { DropDownlist DRL = this.fklist (i, dr [i] .tostring ()); DRL.ID = "lrcdr1_" rownum.tostring () "_" colsa [i]; DRL.enabled = false; Tc.Controls.Add (DRL); } Else { Tc.Text = DR [i] .tostring (); } } Else { Tb = new textbox (); Tb.id = "lrctb_" rownum.toString () "_" colsa [i]; Tb.Text = DR [i] .tostring (); Tb.attributes.add ("onfocus", "this.classname = /" lrc_txt_edit / "; this.parentnode.parentnode.bgcolor = '# c1d2ee';"); Tb.attributes.add ("onbrur", "this.classname = /" lrc_txt_normal / "; this.parentNode.ParentNode.bgcolor = '# ffffff';"); ") //tb.attributes.add(" operative ";"); ");"); "); Tb.enabled = false; //tb.attributes.add("style", "border:0; background :url(Images/txt_back.gif) ;width:100;height:20;"); Tb.cssclass = "lrc_txt_hid"; Tc.Controls.Add (TB); } } Else { Tc = new TableCell (); Tc.Text = DR [i] .tostring (); } Tr.cells.Add (TC); } IF (_ISDEL) { Tc = new TableCell (); LinkButton Lkdelone = New LinkButton (); Lkdelone.id = "LKDEL_" ROWNUM; Lkdelone.text = "Delete"; Lkdelone.commandargument = rownum.tostring (); Lkdelone.command = New CommandeventHandler (Lkdelone_Command); Tc.Controls.Add (Lkdelone); Tr.cells.Add (TC); } Base.Rows.Add (TR); ROWNUM ; } }