Binding Data List and data grid
through dataset. Records are displayed as multiple pages in the data
grid.
Imports System.Data.OleDb
Namespace DataGrid_Repeater
Partial Class DataGridExam1
Inherits System.Web.UI.Page
Dim ad As OleDbDataAdapter
Dim d As DataSet
Dim cmd As OleDbCommand
Dim con As OleDbConnection
Inherits System.Web.UI.Page
Dim ad As OleDbDataAdapter
Dim d As DataSet
Dim cmd As OleDbCommand
Dim con As OleDbConnection
#Region " Web Form Designer
Generated Code "
'This call is
required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub
Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal
sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.LoadTry
con = New OleDbConnection("provider=microsoft.jet.oledb.4.0; data source=C:\Inetpub\wwwroot\Sample-Raghavan\DataGrid-Repeater\bin\datas.mdb")
Catch ex As Exception
Response.Write(ex.Message)
End Try
End Sub
End Sub
Sub DGView()
Try
ad = New OleDbDataAdapter("Select * from vote1 order by eid", con)
d = New DataSet
ad.Fill(d)
Dg.DataSource = d
Dg.DataBind()
Catch ex As Exception
Response.Write(ex.Message)
End Try
End Sub
Sub DGEdit(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
Dg.EditItemIndex = e.Item.ItemIndex
Call DGView()
End Sub
Sub DGUpdate(ByVal sender As
Object, ByVal e As DataGridCommandEventArgs)Try
ad = New OleDbDataAdapter("Select * from vote1 order by eid", con)
d = New DataSet
ad.Fill(d)
Dg.DataSource = d
Dg.DataBind()
Catch ex As Exception
Response.Write(ex.Message)
End Try
End Sub
Sub DGEdit(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
Dg.EditItemIndex = e.Item.ItemIndex
Call DGView()
End Sub
Try
Dim s1 As TableCell
Dim s2, s3, s4 As TextBox
s1 = e.Item.Cells(0)
s2 = e.Item.Cells(1).Controls(0)
s3 = e.Item.Cells(2).Controls(0)
s4 = e.Item.Cells(3).Controls(0)
cmd = New OleDbCommand("Update vote1 set ename='" & s2.Text & "', age=" & s3.Text & ", sex='" & s4.Text & "' where eid=" & s1.Text, con)
con.Open()
cmd.ExecuteNonQuery()
con.Close()
Dg.EditItemIndex = -1
Call DGView()
Catch ex As Exception
Response.Write(ex.Message)
End Try
End Sub
Sub DGCancel(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
Dg.EditItemIndex = -1
Call DGView()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call DGView()
End Sub
End Sub
Sub
PGChange(ByVal sender As Object, ByVal e As DataGridPageChangedEventArgs)
Dg.CurrentPageIndex = e.NewPageIndex
Call DGView()
End Sub
Dg.CurrentPageIndex = e.NewPageIndex
Call DGView()
End Sub
Private Sub
Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button2.Click
Try
ad = New OleDbDataAdapter("Select * from vote1 order by eid", con)
d = New DataSet
ad.Fill(d)
Dl.DataSource = d
Dl.DataBind()
Catch ex As Exception
Response.Write(ex.Message)
End Try
End Sub
End Class
Try
ad = New OleDbDataAdapter("Select * from vote1 order by eid", con)
d = New DataSet
ad.Fill(d)
Dl.DataSource = d
Dl.DataBind()
Catch ex As Exception
Response.Write(ex.Message)
End Try
End Sub
End Class
End Namespace
OUTPUT