Dynamically generate ASP.NET controls

zhaozj2021-02-16  63

public void CreateDataGrid () {DataTable flowTable = new WorkFlowBLL () GetFlowTableByCode (FunctionCode);. foreach (DataRow dataRow in flowTable.Rows) {Table table = new Table (); table.CellPadding = 0; table.CellSpacing = 0; table .Width = unit.percentage (98); Table.Attributes.add ("align", "center"); table.attributes.add ("style", "Height: expness (Document.Body.OffsetHeight-Toolbar.OffsetHeight- SpaceBar.offsetHeight-33) ")") ")"); table.cssclass = "plpanelunselect"; table.attributes.add ("imagessrc", "images / contact.gif"); table.attributes.add ("panelcaption", (String) DataRow ["BMC"]); TableRow tableRow = new tablerow (); Tablecell TableCell = new TableCell (); Tablecell.VerticalAlign = VerticalALIGN.TOP; Panel Panel = new panel (); panel.attributes.add ("style", " Overflow: AUTO; Width: 100%; Height: 100% "); DataGrid = New DataGrid (); DataGrid.BorderWidth = 0; DataGrid.Id = (String) DataRow [" BDM "]; DataGrid.enableViewsta TE = false; dataGrid.width = unit.percentage (100); DataGrid.font.size = fontunit.parse ("12px"); dataGrid.style ["border-collapse"] = "none"; dataGrid.ItemDatabaseD = new DataGridItemEventHandler (dataGrid_ItemDataBound);. dataGrid.DataSource = new WorkFlowBLL () GetFlowDataByCode (FunctionCode, (string) dataRow [ "BDM"], DataCode); dataGrid.DataBind (); panel.Controls.Add (dataGrid); tableCell.Controls .Add (panel); Tablelow.cells.Add (TableCell); Table.Rows.Add (TableRow);

placeHolder.Controls.Add (table);}} private void dataGrid_ItemDataBound (object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) {if ((e.Item.ItemType == ListItemType.Item) || (e.Item .ItemType == ListItemType.AlternatingItem)) {HtmlInputText InputText = new HtmlInputText (); InputText.Attributes.Add ( "class", "clsinput"); InputText.Value = e.Item.Cells [1] .Text; // GetFlowWrite E.Item.cells [1] .controls.add (InputText);} for (int i = 0; i {

IF (E.Item.ItemType == ListItemType.Header)

{

E.Item.cells [i] .attributes.add ("class", "rtitle");

}

Else {

E.Item.attributes.add ("Class", "IRBody");

E.Item.attributes.add ("overclassname", "irbodyover");

E.Item.attributes.add ("CssClick", "IRBodyClick");

}

E.Item.cells [i] .attributes.add ("align", "center");

E.Item.cells [i] .attributes.add ("width", convert.tostring (100 / E.Item.Cells.count) "%");

E.Item.cells [i] .attributes.add ("nowrap", "true");

}

}

转载请注明原文地址:https://www.9cbs.com/read-19213.html

New Post(0)