Step 1:
Create a new page and place one show table panel and one edit table panel on the page. The show table
panel is used to display the SourceTBL data and the Edit Table panel is used to save the copied data in
TargetTBL. Now you must decide if you want to allow users to modify the updated information after it has
been copied to the TargetTBl table panel. If you want to block this option, change the display properties
of each column to literal and make sure you select the "save to database" option in the Page Properties
dialog.
Step 2:
Add a button to the SourceTBL table control. This button is used to copy the selected records to the TargetTBL.
In this example, this button is called "Button".
Step 3:
Create two public (shared) array lists at the TargetTBlTableControl class. Name the first array list: NewDataToAdd,
and the second list: OriginalDataSource. The first list is used to store the selected records to copy for use at the
DataBind method of this class. Use the second list to store the original DataSource of the table when data is loaded
from the database using the LoadData method.
Once this is complete your top lines of code in this class are:
Public Class TargetTBlTableControl
Inherits BaseTargetTBlTableControl
Public Shared NewDataToAdd As ArrayList
Public Shared OriginalDataSource As ArrayList
|
Step 4:
Override the TargetTBLTableControl LoadData Method by implementing the following code:
Public Overrides Sub loaddata()
MyBase.LoadData()
If IsNothing(OriginalDataSource) Then
If Not IsNothing(DataSource) Then
OriginalDataSource = New ArrayList(Me.DataSource)
Else
OriginalDataSource = New ArrayList
End If
Else
OriginalDataSource = New ArrayList(Me.DataSource)
End If
End Sub
|
Once we load the data, we maintain its information in the global OriginalDataSource variable that we declared previously.
Step 5:
In this step we need to override the targetTBLTableControl.DataBind method. Our new DataBind method tests to see if there
is new data to add to the DataSource in the NewDataToAdd variable. If new data exists, add these records to this table datasource
object and bind the controls for proper display. The code for the new Databind method is:
Public Overrides Sub DataBind()
If Not IsNothing(NewDataToAdd) Then
If NewDataToAdd.Count > 0 And Not IsNothing(OriginalDataSource) _
Then
OriginalDataSource.AddRange(NewDataToAdd)
Me.DataSource = _
DirectCast(OriginalDataSource.ToArray(GetType(TargetTBlRecord)), _
TargetTBlRecord())
End If
NewDataToAdd.Clear()
End If
MyBase.DataBind()
End Sub
|
Step 6:
Tie everything together by writing the button click method! The button click method processes the selected
records of the sourceTBl table control. Add the button click method to the NewDataToAdd variable of the TargetTBL
table control and call the targetTBL table control Databind to refresh its data.
Public Overrides Sub Button_Click(ByVal sender As Object, _
ByVal args As EventArgs)
Dim MySelectedSourceRecords() As sourceTblTableControlRow = _
Me.GetSelectedRecordControls
Dim TargetControl As TargetTBlTableControl = _
CType(Me.Page.FindControlRecursively("TargetTblTableControl"), _
TargetTBlTableControl)
Dim SourceREcord As sourceTblTableControlRow
Dim TargetREcord As TargetTBlRecord
Dim TargetDataList As ArrayList
TargetDataList = New ArrayList
For Each SourceREcord In MySelectedSourceRecords
TargetREcord = New TargetTBlRecord
TargetREcord.Age = CInt(SourceREcord.Age.Text)
TargetREcord.Name = SourceREcord.Name.Text
SourceREcord.sourceTblRecordRowSelection.Checked = False
TargetDataList.Add(TargetREcord)
Next
If Not IsNothing(TargetDataList) And TargetDataList.Count > 0 Then
If Not IsNothing(TargetTBlTableControl.NewDataToAdd) Then
TargetTBlTableControl.NewDataToAdd.Clear()
TargetTBlTableControl.NewDataToAdd = TargetDataList
Else
TargetTBlTableControl.NewDataToAdd = New ArrayList
TargetTBlTableControl.NewDataToAdd = TargetDataList
End If
TargetControl.DataBind()
End If
End Sub
|
|