【问题标题】:How to insert a new row between another rows in gridview boundfield?如何在gridview boundfield的另一行之间插入新行?
【发布时间】:2016-01-18 11:56:27
【问题描述】:

我有一个gridview,如下图所示:

在这个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()

非常感谢!

【问题讨论】:

  • 您可以在数据源中添加新行并将该数据源重新分配给gridview。
  • 在页脚是,但不在两行之间。

标签: asp.net vb.net gridview


【解决方案1】:

试试这个

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() 

【讨论】:

  • 对于 vb.net,你知道吗?
  • 新行不是'system.web.ui.webcontrols.Gridview'的成员
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-29
  • 1970-01-01
相关资源
最近更新 更多