Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If GridView1 Is Nothing Then
GridView1.Visible = False
Else
GridView1.Visible = True
End If
End Sub
Function getDatatable() As DataTable
Dim dt As DataTable = Session("dtSource")
If dt Is Nothing Then
dt = New DataTable()
dt.Columns.Add("test")
dt.Columns.Add("test2")
dt.Columns.Add("ลบ")
Session("dtSource") = dt
End If
Return dt
End Function
Sub bindDatatable(ByVal dt As DataTable)
GridView1.DataSource = dt
GridView1.DataBind()
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dt As DataTable = getDatatable()
Dim dr As DataRow = dt.NewRow
Dim delButton As ImageButton = New ImageButton()
delButton.ImageUrl = ("~/images/del.png")
dr("test") = TextBox1.Text
dr("test2") = TextBox2.Text
dr("ลบ") = ???????
dt.Rows.Add(dr)
bindDatatable(dt)
End Sub
ผมสร้าง Control ImageButton ผ่าน Codebehide ฮะ
แล้วตอนเอาไปใส่ ใน datarow ต้องทำไงครับ
Tag : .NET, Web (ASP.NET), VB.NET, VS 2010 (.NET 4.x)