Hi,
See this code...
In your client code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" language="javascript">
function DeleteData() {
return confirm("Are you sure you want to delete this record");
}
function EditData() {
return confirm("Are you sure you want to edit thise record");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<tr>
<td>
<asp:GridView ID="grdCategory" runat="server" AutoGenerateColumns="False" Height="190px"
Width="538px" EnableModelValidation="True">
<columns>
<asp:BoundField HeaderText="ID" DataField="CourseCatID" ItemStyle-HorizontalAlign="Left"
HeaderStyle-HorizontalAlign="Left">
<HeaderStyle HorizontalAlign="Left"></HeaderStyle>
<itemstyle horizontalalign="Left"></itemstyle>
<asp:TemplateField HeaderText="Course Category" ItemStyle-HorizontalAlign="Left"
HeaderStyle-HorizontalAlign="Left">
<itemtemplate>
<asp:Label ID="lblCourseCatName" runat="server" Text='<%# Eval("CourseCatName")%>'>
</itemtemplate>
<HeaderStyle HorizontalAlign="Left"></HeaderStyle>
<itemstyle horizontalalign="Left"></itemstyle>
<asp:TemplateField HeaderText="Edit" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center">
<itemtemplate>
<asp:LinkButton ID="lnkCourseCatID" runat="server"
PostBackUrl='<%#"CourseList.aspx?ID=" & Eval("CourseCatID")%>'
Text="Edit Courses">
</itemtemplate>
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
<itemstyle horizontalalign="Center"></itemstyle>
<asp:TemplateField HeaderText="Delete" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center">
<itemtemplate>
<asp:ImageButton ID="ImageDelete" ImageUrl="../Images/Delete.png" runat="server"
CausesValidation="false" OnClientClick="return DeleteData();" CommandName="cmdDelete"
CommandArgument='<%# Eval("CourseCatID") %>' />
</itemtemplate>
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
<itemstyle horizontalalign="Center"></itemstyle>
</columns>
</td>
</tr>
</div>
</form>
</body>
</html>
In your code behind:
''' <summary>
''' This should be in your BusinessObject Layer ->Entity
''' </summary>
''' <remarks></remarks>
Public Class TrainingPlan
#Region "Defined private Variables"
Private _courseCatID As Integer
Private _courseCatName As String
#End Region
#Region "Defined public properties"
Public Property CourseCatID() As Integer
Get
Return _courseCatID
End Get
Set(ByVal value As Integer)
_courseCatID = value
End Set
End Property
Public Property CourseCatName() As String
Get
Return _courseCatName
End Get
Set(ByVal value As String)
_courseCatName = value
End Set
End Property
#End Region
#Region "The Constructor"
' Without parameter
Public Sub New()
End Sub
#End Region
End Class
Partial Class _Default
Inherits System.Web.UI.Page
Dim _trainingplantemplateDAL As New List(Of TrainingPlan)
Protected Sub grdCategory_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles grdCategory.RowCommand
If e.CommandName = "cmdDelete" Then
Dim coursecatId As String = Convert.ToString(e.CommandArgument)
''Your code for deletetion is here....
''...
End If
_trainingplantemplateDAL = GetTrainigPlan()
CategoryBindGrid(_trainingplantemplateDAL)
End Sub
Protected Sub lnkCourseCatID_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim x As String
End Sub
Protected Sub grdCategory_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdCategory.Load
If Not IsPostBack Then
_trainingplantemplateDAL = GetTrainigPlan()
CategoryBindGrid(_trainingplantemplateDAL)
End If
End Sub
Protected Sub CategoryBindGrid(ByVal trainingplantemplateDAL As List(Of TrainingPlan))
Me.grdCategory.DataSource = trainingplantemplateDAL
Me.grdCategory.DataBind()
End Sub
Public Function GetTrainigPlan() As List(Of TrainingPlan)
''This should be your DAL to full-out records
'' Just to show records in grid...
Dim tempRec1 As New TrainingPlan()
tempRec1.CourseCatID = 10
tempRec1.CourseCatName = "Computer Science"
_trainingplantemplateDAL.Add(tempRec1)
''2
Dim tempRec2 As New TrainingPlan()
tempRec2.CourseCatID = 11
tempRec2.CourseCatName = "BSBA Acounting"
_trainingplantemplateDAL.Add(tempRec2)
Return _trainingplantemplateDAL
End Function
End Class
Please remenber to vote as answer if could help...
Regards,
Algem