Torna al Thread

Imports System.Data.oledb imports system.data Public Class HierarGridDemo Inherits System.Web.UI.Page Dim ds As New DataSet() Protected WithEvents HG1 As DBauer.Web.UI.WebControls.HierarGrid 'SUB DEL PAGE_LOAD Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If (Not Me.IsPostBack) Then Origine() binda() End If End Sub 'SUB DEL DATABINDING Sub binda() HG1.DataSource = ds HG1.DataMember = "table1" HG1.DataBind() End Sub 'SUB DEL L'ORIGINE DATAGRID Sub Origine() Dim conn As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("mdb-database/lafer.mdb")) Dim Adapter As New OleDbDataAdapter("SELECT * FROM tab_sup_cat", conn) Dim Adapter2 As New OleDbDataAdapter("Select * from tab_cat", conn) '("Select tabella1.id, tabella2.campofiglio from tabella1,tabella2 where tabella1.Id=tabella2.rif", conn) Dim Adapter3 As New OleDbDataAdapter("Select * from tab_sotto_cat", conn) '("Select tabella2.id, tabella3.campofiglio from tabella2,tabella3 where tabella2.Id=tabella3.rif", conn) Adapter.Fill(ds, "table1") 'sup_cat Adapter2.Fill(ds, "table2") 'cat Adapter3.Fill(ds, "table3") 'sotto_cat Dim Parent As DataColumn Dim Child As DataColumn Parent = ds.Tables("table1").Columns("ID_sup_cat") Child = ds.Tables("table2").Columns("id_sup_cat") Dim dr As DataRelation = New DataRelation("newrelation", Parent, Child, False) ds.Relations.Add(dr) Parent = ds.Tables("table2").Columns("ID_cat") Child = ds.Tables("table3").Columns("id_cat") dr = New DataRelation("newrelation2", Parent, Child, False) ds.Relations.Add(dr) End Sub 'SUB ELIMINA Sub EliminaDataGrid(ByVal sender As Object, ByVal e As DataGridCommandEventArgs) End Sub 'SUB MODIFICA Sub ModificaDataGrid(ByVal sender As Object, ByVal e As DataGridCommandEventArgs) HG1.EditItemIndex = e.Item.ItemIndex Origine() binda() End Sub 'SUB ANNULLA Sub AnnullaDataGrid(ByVal sender As Object, ByVal e As DataGridCommandEventArgs) HG1.EditItemIndex = -1 binda() End Sub 'SUB AGGIORNA Sub AggiornaDataGrid(ByVal sender As Object, ByVal e As DataGridCommandEventArgs) Dim Conn As Data.OleDb.OleDbConnection Dim MySQL3 As String Dim MyCmd As Data.OleDb.OleDbCommand Dim id_sup_cat, nome_sup_cat As String id_sup_cat = CType(e.Item.Cells(1).Controls(1), Label).Text nome_sup_cat = CType(e.Item.Cells(2).Controls(0), TextBox).Text Conn = New Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("mdb-database/lafer.mdb")) Conn.Open() MySQL3 = "UPDATE tab_sup_cat SET nome_sup_cat = '" & nome_sup_cat & "' WHERE ID_sup_cat = " & id_sup_cat MyCmd = New Data.OleDb.OleDbCommand(MySQL3) MyCmd.Connection = Conn MyCmd.ExecuteNonQuery() HG1.EditItemIndex = -1 Origine() binda() End Sub Private Sub HG1_TemplateSelection(ByVal sender As Object, ByVal e As DBauer.Web.UI.WebControls.HierarGridTemplateSelectionEventArgs) Handles HG1.TemplateSelection Select Case (e.Row.Table.TableName) Case "table2" e.TemplateFilename = "file2.ascx" End Select End Sub Sub HG1_Paging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) HG1.CurrentPageIndex = e.NewPageIndex binda() End Sub End Class
Copyright © dotNetHell.it 2002-2025
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5