Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
Data Repeater With .net
Author:
Gehan Fernando
E-mail:
Click to e-mail author
Submitted:
11/14/2008
Version:
VB 2008
Compatibility:
VB 2008
Category:
Databases
Views:
23600
Use data repeater control to display collection of data very easily.
Declarations:
Imports System Imports System.Data Imports System.Data.SqlClient 'Author :- Gehan Fernando 'Description :- Use DataRepeator Control 'Date :- 14/Nov/2008 'Mail :- f.gehan@gmail.com , gehan_g7@yahoo.com 'Note :- before you run install Visual Basic .NET Power Tools from microsoft site
Code:
Public Class FormDataRepeater Private _emptable As DataTable = Nothing Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.Cursor = Cursors.WaitCursor Try _emptable = Employees.EmployeesData().Tables(0) TextBoxFirstName.DataBindings.Add("Text", _emptable, "FirstName") TextBoxLastName.DataBindings.Add("Text", _emptable, "LastName") TextBoxAddress.DataBindings.Add("Text", _emptable, "Address") TextBoxNotes.DataBindings.Add("Text", _emptable, "Notes") PictureBoxEmployee.DataBindings.Add("Image", _emptable, "Photo") DataRepeaterEmployee.DataSource = _emptable Catch ex As Exception MessageBox.Show(ex.Message, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error) End Try Me.Cursor = Cursors.Default End Sub Private Sub DataRepeaterEmployee_DrawItem(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.PowerPacks.DataRepeaterItemEventArgs) Handles DataRepeaterEmployee.DrawItem If e.DataRepeaterItem.ItemIndex Mod 2 = 0 Then e.DataRepeaterItem.BackColor = Color.FromArgb(213, 224, 211) Else e.DataRepeaterItem.BackColor = SystemColors.Control End If End Sub End Class Public Class Employees Private Shared _con As SqlConnection = Nothing Private Shared _com As SqlCommand = Nothing Private Shared _dap As SqlDataAdapter = Nothing Private Shared _dset As DataSet = Nothing Private Shared _sqlstr As String = "Data Source=MYPC\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True" Public Shared Function EmployeesData() As DataSet Try _con = New SqlConnection(_sqlstr) _con.Open() _com = New SqlCommand() With _com .Connection = _con .CommandType = CommandType.Text .CommandText = "SELECT FirstName,LastName,Address,Photo,Notes FROM Employees ORDER BY FirstName,LastName" End With _dap = New SqlDataAdapter(_com) _dset = New DataSet("DSetEmployees") _dap.Fill(_dset) Catch ex As Exception _dset = Nothing Throw ex End Try Return _dset End Function End Class
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement