[RESOLVED] Adding rows to GridView programatically
Today is the first day i hav to use the new ASP.NET 2.0 GridView control. After searching all over the place, it seems that one cannot programatically add rows to GridView like one can with DataGrid. Why can`t i add rows programatically? And is it possible with some trick to add rows? Makes me feel like wanting to go back to using DataGrid
You can populate a 'DataTable' with your data then bind that to the gridview (you can programatically add rows to the datatable).
Private Sub BindData()
gridview1.DataSource = GetData()
Protected Function FormatDataTable() as DataTable
Dim dt as DataTable = New DataTable()
' Create Columns
Protected Function GetData() as DataTable
Dim dt as DataTable = FormatDataTable()
Dim dr as DataRow
' Populate the datatable with your data (put this in appropriate loop)
dr = dt.NewRow
dr("id") = "1"
dr("txt") = "Hi"
' Add the row
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rich Cook