首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

如何在gridview中插入数据而且数据显示在gridview的第一行

2012-01-14 
怎么在gridview中插入数据而且数据显示在gridview的第一行那位有代码支援一下吧,我都快着急的抓狂了 [解决

怎么在gridview中插入数据而且数据显示在gridview的第一行
那位有代码支援一下吧,我都快着急的抓狂了


[解决办法]
Public Class Form1
Private dtt As New DataTable
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
CtlDataGrid1.DataSource = Nothing

dtt.Columns.Add( "No. ", GetType(System.Int32))
dtt.Columns.Add( "Name ", GetType(System.String))
dtt.Columns.Add( "Birthday ", GetType(System.DateTime))

For i As Integer = 0 To 20
dtt.Rows.Add(dtt.NewRow)
dtt.Rows(i).Item( "No. ") = i
dtt.Rows(i).Item( "Name ") = "Name_ " & i.ToString.PadLeft(3, "0 "c)
dtt.Rows(i).Item( "Birthday ") = Today.AddDays(i)
Next

CtlDataGrid1.DataSource = dtt
End Sub


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

CtlDataGrid1.ReadOnly = False
CtlDataGrid1.AllowUserToAddRows = True
Dim dr As DataRow = dtt.NewRow
dr.Item( "No. ") = 99
dr.Item( "Name ") = "Name_99 "
dr.Item( "Birthday ") = Today.AddDays(99)

dtt.Rows.InsertAt(dr, 0)
CtlDataGrid1.Refresh()
End Sub
End Class

热点排行