【问题标题】:asp.net gridview without database没有数据库的asp.net gridview
【发布时间】:2013-05-09 07:39:48
【问题描述】:

大家好,我有一个问题。有什么方法可以在不使用数据库的情况下在 asp.net 中填充 gridview?我正在使用 gridview 来显示信息,但我发现每次尝试向网格中插入更多行时,最后一行都会被新行更改并覆盖数据

我正在使用以下代码:

Dim dtsetinform As New DataSet
Dim datatableinfo As New DataTable("fill")

   Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

   dtsetinform.Tables.Add(datatableinfo ) 
   gridfactura.DataSource = datatableinfo 
   datatableinfo.Columns.Add("Name") '
   datatableinfo.Columns.Add("Quantity")
   datatableinfo.Columns.Add("Price")

   Session("fill") = datatableinfo 

End Sub

Public Sub agregarfilas(ByVal total As Integer)

   datatableinfo = Session("fill")

   Dim row As DataRow = datatableinfo .NewRow
   row("Name") = ddserviciotxt.Text 
   row("Quantity") = cantidadtxt.Text
   row("Price") = total
   datatableinfo .Rows.Add(row)

   ViewState("tablainViewState") = datatableinfo 
   datatableinfo .AcceptChanges()
   gridfactura.DataSource = datatableinfo 

   gridfactura.DataBind()

End Sub

Protected Sub btnagregar_Click(sender As Object, e As EventArgs) Handles btnagregar.Click
Dim result As Integer
Dim price As Integer = preciotxt.Text

Dim quantity As Integer = cantidadtxt.Text

result = price * quantity 
agregarfilas(result)

End Sub

【问题讨论】:

    标签: asp.net gridview postback


    【解决方案1】:

    你需要把代码在页面加载中

    if not Page.IsPostBack then
    your code
    end if
    

    【讨论】:

    • 哇,非常感谢!现在网格显示了我想要的数据。谢谢!
    猜你喜欢
    • 2012-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-21
    • 1970-01-01
    • 2012-06-11
    相关资源
    最近更新 更多