Click here to Skip to main content
12,406,528 members (27,451 online)
Rate this:
Please Sign up or sign in to vote.
See more: ASP.NET
<pre lang="c#">
Parent Grid row bound Event:

    protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
if (e.Row.RowType == DataControlRowType.DataRow)
string DepartmentID = gvDepartment.DataKeys[e.Row.RowIndex].Value.ToString();
GridView gvCompleated = e.Row.FindControl("gvCompleated") as GridView;
GridView gvRunning = e.Row.FindControl("gvRunning") as GridView;
TaskGateway employeeGateObj = new TaskGateway();
gvRunning.DataSource = employeeGateObj.GetTaskTable(DepartmentID);
gvCompleated.DataSource = employeeGateObj.GetPendingTaskTable(DepartmentID);
foreach (GridViewRow gr in gvCompleated.Rows)
if (gr.RowType == DataControlRowType.DataRow)
LinkButton lnkbtnresult = (LinkButton)gr.Cells[0].FindControl("requestID3");
if (lnkbtnresult != null)
lnkbtnresult.Click += new System.EventHandler(requestID3_Click);

foreach (GridViewRow gr in gvRunning.Rows)
if (gr.RowType == DataControlRowType.DataRow)
LinkButton lnkbtnresult = (LinkButton)gr.Cells[0].FindControl("requestID3");
if (lnkbtnresult != null)
lnkbtnresult.Click += new System.EventHandler(requestID3_Click);

The above code i did on the parent grid row bound, in the parent grid i have two child grid view one is gvcompleted and another is gvrunning,and i have link button on each child grid view but i am not able to handle click event of link button, even i tried to do on the child grid rowbound and rowcommand event but they are not working.
Posted 17-Jan-13 7:37am
Updated 17-Jan-13 17:05pm
OPees 17-Jan-13 13:39pm
Thanks in advance..!!
richcb 17-Jan-13 15:24pm
You have not explained anything or even asked a question. This is just a code dump. Use the "Improve Question" widget and formulate a specific question regarding your goal.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

If you want to get the click event of link button then there is simple code, user RowCommad event of grid view:
Assume gridview is like
<asp:gridview id="grvTest" runat="server" xmlns:asp="#unknown">
      <asp:linkbutton id="lnk" runat="server" text="Test" commandname="TestCommand" />
and your aspx.cs file contense the event RowCommad like :
Protected Void grvTest_RowCommand(object sender, GridViewCommandEventArgs e) 
    If(e.CommandName == "TestCommand")
      ///Do your code here

if helpful to you, accept the solution
OPees 18-Jan-13 0:28am
my Grid is like this
<asp:GridView ID="gvDepartment" runat="server" AutoGenerateColumns="False" BorderColor="Transparent"
Width="100%" BorderWidth="0px" BorderStyle="None" DataKeyNames="Dept_ID" OnRowDataBound="OnRowDataBound" Height="266px" onrowcommand="gvDepartment_RowCommand1" >

<asp:TemplateField ControlStyle-BorderStyle="None" ControlStyle-Width="5%">

<img id="imagepnlid-<%# Eval("Dept_ID") %>" alt="Click to show/hide Department" border="0"
src="../plus.png" />


<asp:BoundField ItemStyle-Width="" DataField="DepartmentName" HeaderText="Department"


<td colspan="100%">
<div id="pnlid-<%# Eval("Dept_ID") %>" style="display: none; position: relative; left: 25px;">

<asp:GridView ID="gvRunning" runat="server" AutoGenerateColumns="false" CssClass="ChildGrid" OnRowDataBound="OnRowDataBound1" onrowcommand="gvDepartment_RowCommand" >

<asp:TemplateField HeaderText="Task ID">

<asp:LinkButton ID="requestID3" runat="server" CommandName="COUNT_REQUEST_ID" CommandArgument="gvRuning" OnClick="requestID3_Click"
Text='<%# Eval("Task_ID")%>'>
<asp1:ModalPopupExtender ID="mp1" runat="server" PopupControlID="Panel1" TargetControlID="requestID3"
CancelControlID="btnClose" BackgroundCssClass="modalBackground">

<asp:BoundField DataField="Task_Name" HeaderText="Task Name" SortExpression="Task_Name" />
<asp:BoundField DataField="Discription" HeaderText="Description" SortExpression="Discription" />
<asp:BoundField DataField="Star_Date" HeaderText="Start Date" SortExpression="Star_Date" />
<asp:BoundField DataField="End_Date" HeaderText="End Date" SortExpression="End_Date" />
<asp:BoundField DataField="Delay_Date" HeaderText="Delay Date" SortExpression="Delay_Date" />


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.160730.1 | Last Updated 18 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100