在rowdatabound事件里写,如还有什么问题请留言
你可能会用到GridView.rows(i).cell(a).controls.add()

解决方案 »

  1.   

    看看这个适合你吗?
            private void CreateTable()
            {//动态创建表格
                DataSet ds = this.ReadColumnBind();
                if (ds != null && ds.Tables[0].Rows.Count > 0)
                {
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        Table t = new Table();
                        t.Width = Unit.Percentage(100);
                        t.ID = "t" + i.ToString();
                        ph.Controls.Add(t);
                        TableRow tr = new TableRow();
                        t.Rows.Add(tr);
                        TableCell tc = new TableCell();
                        tc.HorizontalAlign = HorizontalAlign.Center;
                        tc.Width = Unit.Pixel(105);
                        tr.Cells.Add(tc);
                        tc.Text = ds.Tables[0].Rows[i]["ColumnName"].ToString() + ":";
                        TableCell tc2 = new TableCell();
                        tc2.HorizontalAlign = HorizontalAlign.Left;
                        //tc2.Width=Unit.Pixel(424);
                        tr.Cells.Add(tc2);
                        TextBox txtbox = new TextBox();
                        if (ds.Tables[0].Rows[i]["ColumnType"].ToString() == "memo")
                        {
                            txtbox.TextMode = TextBoxMode.MultiLine;
                            txtbox.Columns = 50;
                            txtbox.Rows = 6;
                        }
                        txtbox.ID = ds.Tables[0].Rows[i]["ColumnMing"].ToString();
                        tc2.Controls.Add(txtbox);
                    }
                }
            }也可以使用Ajax如果需要给我留言QQ155087442