Not the best piece of code in the world, but, you can have a look at the following simple implementation and follow a similar approach:
Note : Pardon the C# code. I don't know VB.NET and you have to convert these codes to VB.NET to run
Aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" 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>
</head>
<body>
<form id="form1" runat="server">
<div>
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
Width="215px" OnRowCommand="GridView1_RowCommand"
onrowdatabound="GridView1_RowDataBound">
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False"
CommandName="Edit" Text="Edit"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</div>
</form>
</body>
</html>
And, CodeBehind (Written in C# as I do not know VB.net, please convert into VB.NET)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
public partial class _Default : System.Web.UI.Page
{
public class Person
{
public int Id
{
get;
set;
}
public string Name
{
get;
set;
}
public Person(int Id, string Name)
{
this.Id = Id;
this.Name = Name;
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
IList items = new ArrayList();
items.Add(new Person(1, "Peter"));
items.Add(new Person(2, "John"));
items.Add(new Person(3, "Shubho"));
GridView1.DataSource = items;
GridView1.DataBind();
}
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Edit")
{
int userId = Convert.ToInt32(e.CommandArgument);
Response.Redirect(string.Format("CreateUser.aspx?Id={0}",userId));
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton link = e.Row.FindControl("LinkButton1") as LinkButton;
if (link != null)
{
link.CommandArgument = ((Person)e.Row.DataItem).Id.ToString();
}
}
}
}
I provided you the codes because somehow I feel you are kind of new in Asp.net and thought this will help you.