Full edit WebGrid Control Lrcgrid (6)--Control rendering

Source: Internet
Author: User
Tags count sort tostring client
web| control full Edit WebGrid control Lrcgrid (6)--Control rendering

Creating child controls

Override the CreateChildControls () procedure to invoke the method that creates the child control rebuild ()
The CreateChildControls () method is invoked whenever the ASP.net page framework needs to create the control tree, and the method invocation is not limited to the specific stage of the control lifecycle. For example, you can call CreateChildControls when the page is loaded, during the binding data, or during the rendering process

protected override void CreateChildControls ()
{
This. ReBuild ();
}

Overrides the OnPreRender (EventArgs e) procedure, which registers the client script block, which causes the user to return to the focus jump, and the commented out part is the method of using the resource file.
protected override void OnPreRender (EventArgs e)
{
Base. OnPreRender (e);
if (THIS._ISTABCHG)
{
if (! Page.isclientscriptblockregistered ("Lrc_chgtab"))
{
String str_chgtab = @ "<script language= ' javascript ' event= ' onkeydown ' for= ' document ' >
<!--
if (event.keycode==13 && event.srcelement.type!= ' button ' && event.srcelement.type!= ' Submit ' & & event.srcelement.type!= ' reset ' && event.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);
}
*/
}

The ReBuild () method, which changes the properties of a control at run time, calls this method to reconstruct the control, which calls a series of internal procedures: Managing view state, clearing the control, initializing the dataset, creating a header row, creating a data row, creating an action row, and so on:

<summary>
Re-construct a control
</summary>
public void ReBuild ()
{
if (this. CurrentPageIndex = =-1)
This. CurrentPageIndex = 0;
This. Controls.clear ();
This. Clearchildviewstate ();
This. Attributes.Add ("Isdel", this._isdel.tostring ());
This. Attributes.Add ("Isadd", this._isadd.tostring ());
This. Dbset = null;
Base. CreateChildControls ();
Create header row
Buildtitle ();
Initdataset ();
if (this. Dbset!= null)
{
if (this. DbSet.Tables.Count > 0)
{
if (this. Dbset.tables[0]. Rows.Count > 0)
{
To create a data row
Buildcol ();
}
}
}
Create an action line
Buildoper ();
}

Create the header row Buildtitle () method, header row also header, according to the set caption content property Colsa, here I set the header text for each column to trigger the server-side sort event LinkButton and add a htmlanchor to each editable column header. This htmlanchor invokes the client script Chgedit () function, (see the full Edit WebGrid control Lrcgrid (4)-Script library and style sheet) to toggle a column in the table between normal and edit mode, if the property settings allow deletion, LinkButton that will add delete all on the header row

The table header effect is shown in the following illustration:

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<colsa.length;i++)
{
TC = new TableCell ();
Tc. BackColor = _titcolor;
Sort
if (_issort)
{
Full edit
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 = "Delete all";
Lk.command + = new Commandeventhandler (Lkdel_command);
Tc. Controls.Add (LK);
Tr. Cells.add (TC);
}
This. Rows.Add (TR);
}
}

Creates a data row Buildcol () method that traverses all the items in the dataset table, displays the records and fields from the data source as rows and columns of the form, adds different controls to the table items, and binds the values from the data source to the controls, based on the properties you set.

Non-editable columns: Write data item values directly to Tablecell.text
Non-Foreign



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.