如何在gridview boundfield中的另一行之间插入新行?

时间:2016-01-18 11:56:27

标签: asp.net vb.net gridview

我有gridview如下图:

enter image description here

在这个gridview中我想引入一个新行,它没有任何完全脱离最后一个" Grand Total"那里放一个变量我的。

但问题是,如何引入新的一行呢?

我的代码是:

        Dim Qty As Double = 0
        Dim CostCategory As Double = 0
        Dim AssemblyDate As String = Nothing

        If GridView1.Rows.Count <> 0 Then
            For x As Integer = 0 To GridView1.Rows.Count - 1
                For y As Integer = 0 To GridView1.Columns.Count - 1

                    If y = 0 And GridView1.Rows(x).Cells(1).Text = AssemblyDate Then
                        GridView1.Rows(x).Cells(1).Text = ""
                    End If

                    If GridView1.Rows(x).Cells(1).Text <> Nothing Then
                        AssemblyDate = GridView1.Rows(x).Cells(1).Text
                    End If


                    If y = "9" Then
                        Qty = Convert.ToDouble(GridView1.Rows(x).Cells(9).Text)
                    End If

                    If y = "13" Then
                        CostCategory = Convert.ToDouble(GridView1.Rows(x).Cells(13).Text)
                    End If

                    If y = "14" Then
                        GridView1.Rows(x).Cells(14).Text = Qty * CostCategory
                        GridView1.Rows(x).Cells(14).HorizontalAlign = HorizontalAlign.Center
                    End If

                    If GridView1.Rows(x).Cells(y).Text = "Yes" Then
                        GridView1.Rows(x).Cells(y).BackColor = System.Drawing.Color.LawnGreen

                    ElseIf GridView1.Rows(x).Cells(y).Text = "No" Then
                        GridView1.Rows(x).Cells(y).BackColor = System.Drawing.Color.Red
                    End If
                Next
            Next
End if

在那段代码之前,我有一个查询,我填写了我的gridview:

Dim myQuery As String = SelectQuery & WhereQuery
SqlDataSource1.SelectCommand = myQuery
SqlDataSource1.DataBind()
GridView1.DataSourceID = "SqlDataSource1"
GridView1.DataBind()

非常感谢!

1 个答案:

答案 0 :(得分:0)

尝试使用此

DataRow dr = tblTable.NewRow(); //Create New Row
dr["ColumnName"] = "Legs";              // Set Column Value
tblTable.Rows.InsertAt(dr, 11); // InsertAt specified position

对于VB.Net网格视图

Dim rowNumber As Integer = dGrid.CurrentCell.RowNumber() + 1 
Dim myNewRow As DataRow = myDataTable.NewRow() 
myDataTable.Rows.InsertAt(myNewRow, rowNumber) 
myDataTable.AcceptChanges()