2014/09/10

Asp.Net GridView 動態產生行



新增行:

            Label label = new Label();
            label.Text = "test";
            label.Width = Unit.Pixel(400);

            //修改
            HyperLink linkEditor = new HyperLink();
            linkEditor.Text = "編輯";

            //刪除
            HyperLink linkDelete = new HyperLink();
            linkDelete.Text = "刪除";

            //增加
            HyperLink linkInsert = new HyperLink();
            linkInsert.Text = "增加";

            //新增一行
            TableCell cell = new TableCell();
            cell.Controls.Add(label);
            cell.Controls.Add(linkEditor);
            cell.Controls.Add(linkDelete);
            cell.Controls.Add(linkInsert);

            GridViewRow gridViewRow = new GridViewRow(0, -1, DataControlRowType.DataRow,
                DataControlRowState.Normal);
            gridViewRow.Controls.Add(cell);

            //加入到指定行數
            GridView.Controls[0].Controls.AddAt(index, gridViewRow);

沒有留言:

張貼留言