动态生成asp.net控件

翻译|其它|编辑:郝浩|2004-08-17 10:26:00.000|阅读 1370 次

概述:

# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>


动态生成asp.net控件的代码如下:

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:expression(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.EnableViewState=false;
dataGrid.Width=Unit.Percentage(100); 
dataGrid.Font.Size=FontUnit.Parse("12px");
dataGrid.Style["border-collapse"]="none";
dataGrid.ItemDataBound += new DataGridItemEventHandler(dataGrid_ItemDataBound);
dataGrid.DataSource=new WorkFlowBLL().GetFlowDataByCode(FunctionCode,(string)dataRow["BDM"],DataCode);
dataGrid.DataBind();
panel.Controls.Add(dataGrid); 
tableCell.Controls.Add(panel);
tableRow.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","irTitle"); 
}
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") ;
}
}


标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@evget.com


为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP