动态生成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") ;
   }
  }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值