Click here to Skip to main content
12,952,398 members (44,356 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
<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);
gvRunning.DataBind();
gvCompleated.DataSource = employeeGateObj.GetPendingTaskTable(DepartmentID);
gvCompleated.DataBind();
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
OPees2.7K
Updated 17-Jan-13 17:05pm
v2
Comments
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
 
good
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:
see:
Assume gridview is like
<asp:gridview id="grvTest" runat="server" xmlns:asp="#unknown">
  <asp:templatefield>
    <itemtemplate>
      <asp:linkbutton id="lnk" runat="server" text="Test" commandname="TestCommand" />
    </itemtemplate>
  </asp:templatefield>
</asp:gridview>

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
  Permalink  
v2
Comments
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" >
<columns>
<asp:TemplateField ControlStyle-BorderStyle="None" ControlStyle-Width="5%">
<itemtemplate>

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


<%--<ControlStyle BorderStyle="None">--%><ControlStyle BorderStyle="None"
Width="5%">

<asp:BoundField ItemStyle-Width="" DataField="DepartmentName" HeaderText="Department"
ControlStyle-Width="95%">
<ControlStyle Width="95%">

<asp:TemplateField>
<itemtemplate>
<tr>
<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" >
<columns>
<asp:TemplateField HeaderText="Task ID">
<itemtemplate>
<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" />


</div>
</td>
</tr>

<ControlStyle BorderStyle="None" Width="0%" />


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
OriginalGriff 6,239
CHill60 3,490
Maciej Los 3,083
Jochen Arndt 1,975
ppolymorphe 1,880


Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 18 Jan 2013
Copyright © CodeProject, 1999-2017
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