虽然动态创建DataGrid的代码在网上有很多,但是作为表单提交的时候却不多见?
2006-07-27 16:34
525 查看
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") ;
}
}
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") ;
}
}
相关文章推荐
- 页面上2个按钮,当提交表单的时候调用不同的方法,但是都需要把页面上面的查询条件提交给action
- 出栈序列判定 网上一些代码虽然能AC但是有bug
- 动态创建hidden提交表单并提交
- 利用动态创建层技术实现无冗余代码为表单自动添加错误提示
- VSTS有Bug,分析数据库的维度和维度属性使用中文命名时候,作为报表参数会出错。虽然有解决办法但是头大。
- JQuery动态创建DOM、表单元素的实现代码
- jquery 自动创建form表单提交代码 下拉条 ajax模板代码 添加_移除 属性_样式
- 用javascript动态创建并提交表单form,表格table
- JQuery动态创建表单并提交
- js动态创建Form表单并提交
- JQuery动态创建DOM、表单元素的实现代码
- JQuery动态创建表单并提交
- 杭电1248寒冰王座问题,对比网上代码,虽然AC了,但是代码太过复杂了
- 抽象类和接口作为形式参数 多态 抽象类和接口虽然都不能直接创建对象,但是可以通过多态进行对象的创建
- JavaScript动态创建form表单并提交的实现方法
- IntelliJ IDEA 本地代码提交不到github网站上:github与本地不同步,虽然本地显示提交,但是github网站上看不到
- jQuery动态创建表单并提交
- JQuery动态创建DOM、表单元素的实现代码
- 动态创建表单并提交
- JS动态创建表单post提交