我要实现的功能是:我有N个textbox控件,下面是一个添加按钮,在下面是一个gridview控件,对应关系不用考虑了。
我希望,每次填完所有的textbox后点添加按钮,在gridview中显示一行,当第二次添加时,就再次插入一个新行。类推。如何实现。
我希望,每次填完所有的textbox后点添加按钮,在gridview中显示一行,当第二次添加时,就再次插入一个新行。类推。如何实现。
{...}然后点击按钮事件中引用这个函数就可以了protected void click()
{
...
binddata();
}
将gridview绑定数据库中该表
BUTTON事件内加上重新绑定语句就成
我看过 数据集做的
ds_XX.XXDataTable NDT_A = (_GJList.GJ_Need_DetailDataTable)ViewState["NDT_A"];
然后和正常一样操作
最后绑定
GridView1.DataSource = NDT_A;
GridView1.DataBind();
public static ArrayList ;
row[0]="1";
gridview.Rows.Add(row);
string HeaderBackColor = "#EDEDED";
rowHeader.BackColor = System.Drawing.ColorTranslator.FromHtml(HeaderBackColor);
Literal newCells = new Literal();
newCells.Text = @"表头文字1</th> <th colspan='2'>表头文字2</th> <th colspan='2'>表头文字3</th> <th>表头文字4</th> </tr> <tr bgcolor='" + HeaderBackColor + "'>";
newCells.Text += @" <th colspan='2'>表头文字5</th> <th rowspan='2'>表头文字6</th> <th colspan='2'>表头文字7</th> </tr> <tr bgcolor='" + HeaderBackColor + "'>";
newCells.Text += @" <th>表头文字8</th> <th>表头文字9</th> <th>表头文字10</th> <th>表头文字11</th> <th>表头文字12";
TableCellCollection cells = this.GridView1.Rows[0].Cells; TableHeaderCell headerCell = new TableHeaderCell();
headerCell.RowSpan = 2; headerCell.Controls.Add(newCells);
rowHeader.Cells.Add(headerCell);
rowHeader.Cells.Add(headerCell);
rowHeader.Visible = true;
GridView1.Controls[0].Controls.AddAt(0, rowHeader);
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string tb1 = this.TextBox1.Text;
string tb2 = this.TextBox2.Text;
string tb3 = this.TextBox3.Text;
string tb4 = this.TextBox4.Text;
string tb5 = this.TextBox5.Text;
arrayList.Add(tb1);
arrayList.Add(tb2);
arrayList.Add(tb3);
arrayList.Add(tb4);
arrayList.Add(tb5);
this.GridView1.DataSource = arrayList;
this.DataBind();
}
嘿嘿!你先看下把!大概思路 !我随便写的!代码还可以优化
如果你要着效果的话!你自己优化下代码!
txtNm1.Name = "商品编号";
txtNm1.HeaderText = "商品编号";
this.dgvXiaoshouchupin.Columns.Insert(0, txtNm1); DataGridViewTextBoxColumn txtNm2 = new DataGridViewTextBoxColumn();
txtNm2.Name = "商品规格";
txtNm2.HeaderText = "商品规格";
this.dgvXiaoshouchupin.Columns.Insert(1, txtNm2); DataGridViewTextBoxColumn txtNm3 = new DataGridViewTextBoxColumn();
txtNm3.Name = "数量";
txtNm3.HeaderText = "数量";
this.dgvXiaoshouchupin.Columns.Insert(2, txtNm3);
dgvXiaoshouchupin为datagridview 并添加三列
按钮事件里写如下:
this.dgvXiaoshouchupin.Rows.Add();有点笨但有效