用于在DataGridview中添加行 [英] For Adding row in DataGridview

查看:70
本文介绍了用于在DataGridview中添加行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将数据从一页检索到另一页时''Gridview那个时间页没有刷新...意味着值被加注了,但是系统无法在DataGridview中添加行...那么我该怎么办..? br/>
例如:

When i am retriving data from one page to another page''Gridview that time page not refresh...means value fatched but System can''t add rows in DataGridview...then what can I do..?

for ex:

DataGridViewRow row = new DataGridViewRow();
dgvIndent.Rows.Add();
row = dgvIndent.Rows[RowIndex];
row.Cells["varProductFullCode"].Value = ProductFullCode;


所有方法都用于添加,但是页面无法第二次刷新的问题
我也在使用this.Refresh();但页面未刷新


All method use for add but problem of Page cant refresh Second Time
i am also using this.Refresh(); but page is not Refreshed

推荐答案

小数orderTotal = 0.0m;
十进制税= 0.0m;
受保护的void gvOrderDetail_RowDataBound(object sender,GridViewRowEventArgs e)
{
//TODO:当RowType = DataRow
时,计算orderTotal和税款 如果(e.Row.RowType == DataControlRowType.Footer)
{
//创建行
GridViewRow行=新的GridViewRow
(-1,-1,DataControlRowType.DataRow,DataControlRowState.Normal);
//添加两列
row.Cells.AddRange(CreateCells());
//获取对保存该行的表的引用
表格tbl =(如表格中的行父母);
//将行添加到列表的末尾,但在页脚之前.
tbl.Rows.AddAt(gvOrderDetail.Rows.Count + 1,行);

//不要忘记解释页脚的任何变化.由于我们添加了一行来显示税款,
//税也必须在我们的页脚中说明.计算orderTotal和税额
//是读者的练习.
标签lbl;
lbl =(标签)e.Row.FindControl("lblTotal");
lbl.Text = String.Format("{0:C}",(orderTotal + tax));
}
}

私有TableCell [] CreateCells()
{

TableCell []单元格=新的TableCell [2];
TableCell单元格;
标签lbl;

//订单项列
cell = new TableCell();
lbl = new Label();
lbl.Text =营业税";
cell.Controls.Add(lbl);
单元格[0] =单元格;

//价格列
cell = new TableCell();
lbl = new Label();
lbl.Font.Bold = true;
lbl.Text = tax.ToString("C");
cell.Horizo​​ntalAlign = Horizo​​ntalAlign.Right;
cell.Controls.Add(lbl);
cells [1] =单元格;

返回单元格;
}
decimal orderTotal = 0.0m;
decimal tax = 0.0m;
protected void gvOrderDetail_RowDataBound(object sender, GridViewRowEventArgs e)
{
//TODO: Calculate the orderTotal and the tax when RowType = DataRow
if (e.Row.RowType == DataControlRowType.Footer)
{
//Create the Row
GridViewRow row = new GridViewRow
(-1, -1, DataControlRowType.DataRow, DataControlRowState.Normal);
//Add the two Columns
row.Cells.AddRange(CreateCells());
//get a reference to the table that holds this row
Table tbl = (e.Row.Parent as Table);
//Add the row at the end of the list, but before the footer.
tbl.Rows.AddAt(gvOrderDetail.Rows.Count + 1, row);

//Don''t forget to account for any changes in the footer. Since we added a row to show the tax,
//that tax must also be accounted for in our footer. Calculating the orderTotal and the tax
//is an exercise for the reader.
Label lbl;
lbl = (Label)e.Row.FindControl("lblTotal");
lbl.Text = String.Format("{0:C}", (orderTotal + tax));
}
}

private TableCell[] CreateCells()
{

TableCell[] cells = new TableCell[2];
TableCell cell;
Label lbl;

//The order item column
cell = new TableCell();
lbl = new Label();
lbl.Text = "Sales Tax";
cell.Controls.Add(lbl);
cells[0] = cell;

//The price column
cell = new TableCell();
lbl = new Label();
lbl.Font.Bold = true;
lbl.Text = tax.ToString("C");
cell.HorizontalAlign = HorizontalAlign.Right;
cell.Controls.Add(lbl);
cells[1] = cell;

return cells;
}


这篇关于用于在DataGridview中添加行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆