虽然动态创建DataGrid的代码在网上有很多,但是作为表单提交的时候却不多见?

来源:互联网 发布:河池网络问政 编辑:程序博客网 时间:2024/06/04 08:11

1、这个是动态创建的时候的后端代码,但是怎么显示成表单后提交到服务器端呢?用完全动态的方式

public void CreateDataGrid(DataTable dt)
  {
   DataTable flowTable=dt;   //=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["tableName"].ToString());
    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=dataRow["ID"].ToString();  
    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=dt;  //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<e.Item.Cells.Count;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") ;
     }
     }  

原创粉丝点击