Home > Forum > ASP.NET > Grid view events fired

Grid view events fired

by Thamil   on Oct 01, 2013   Category: ASP.NET  |  Views: 1940    |  Points: 5   |  Gold 

In a grid view there are four columns are there.Where first three column data's are populated from DB.And in the fourth column link button is there it was dynamically added for each row.Suppose if i click the link button nothing is happened.How to fire the event if i click the link button.Can any one advise me.
And I have attached my codings
<asp:LinkButton ID="CompanyID" runat="server" OnClick="lnkView_Click" CommandName="Open" Text="Open"></asp:LinkButton>

if (e.CommandName.Equals("Open"))
catch (Exception ex)


Question posted on behalf of Ranjith Kumar.

Bookmark and Share:
  User Reply  | Ask a question  |   Reply 
  Re :Grid view events fired   
by Thamil
on Oct 1 2013 12:26PM
Points : 10
Hi Ranjtih kumar,

It's simple and easy, create the rowcommand event and when you click on link button in gridview it will fire rowcommand event and do you functionality on this command as show below.

<asp:GridView ID="GVSample" runat="server" AutoGenerateColumns="False" OnRowCommand="GVSample_RowCommand">
<asp:BoundField DataField="DepName" HeaderText="DepName" />
<asp:TemplateField HeaderText="Userprofile">
<asp:LinkButton ID="CompanyID" runat="server" CommandName="Open" Text="Open"></asp:LinkButton>


protected void Page_Load(object sender, EventArgs e)
if (!IsPostBack)
GVSample.DataSource = GetEmpDept();


protected void GVSample_RowCommand(object sender, GridViewCommandEventArgs e)
if (e.CommandName.Equals("Open"))
//Your code goes here..

private DataTable GetEmpDept()
//Get Employee department
DataTable dt = new DataTable();

DataRow rw1 = dt.NewRow();
rw1[0] = "IT";

DataRow rw2 = dt.NewRow();
rw2[0] = "Finance";

DataRow rw3 = dt.NewRow();
rw3[0] = "Security";

return dt;

i hope this will help you.

Recent Post

Latest Posts