The Simplest CRUD Operations for Lookup Tables in ASP.NET - Dealing with DML operations
(Page 5 of 7 )
I included a button with the caption "Add." Actually, it does nothing other than clear the values existing in all the controls. Let us go through the following code:
PrivateSub btnAdd_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnAdd.Click
Me.txtDeptno.Text = ""
Me.txtDname.Text = ""
Me.txtLocation.Text = ""
Me.txtDeptno.Enabled = True
Me.frDept.Visible = True
End Sub
The above simply clears all controls and makes the "editing layout" visible so that you can enter a new record. When the user clicks on "edit" on the datagrid, it will invoke the following method:
PrivateSub ShowEdit(ByVal DeptID As String)
Dim dr As DataRow = db.getDataRow("select * from dept
where deptno=" & DeptID)
If dr Is Nothing Then
Me.lblMsg.Text = "Dept Not found"
Me.lblMsg.Visible = True
Exit Sub
End If
Me.txtDeptno.Text = dr("Deptno")
Me.txtDeptno.Enabled = False
Me.txtDname.Text = dr("Dname")
Me.txtLocation.Text = dr("Loc")
Me.frDept.Visible = True
End Sub
You can understand that the above simply retrieves a record from the database and displays the same on the screen. The button "Cancel" is provided with the following code:
PrivateSub btnCancel_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles btnCancel.Click
Me.frDept.Visible = False
Me.lblMsg.Visible = False
End Sub
The above method simply hides the "editing layout" and existing error messages.
Next: Dealing with DML Operations: continued >>
More ASP.NET Articles
More By Jagadish Chaterjee